0

我正在尝试为我今天安装的 APC 的应用程序构建配置解析器,但是每次我尝试将序列化对象放入存储中时,它都不会进入那里,也不会。(我正在用 apc.php 检查我在 PHP 5.3.16 [我的开发环境] 上的版本 [3.1.8-dev],所以我确信数据不在缓存中)。这就是我将数据传递给缓存器的方式:

// The data before the caching
array (
'key' => md5($this->filename),
'value' => serialize($this->cfg)
);

// The caching interface
function($argc){
$key = $argc['key'];
Cache\APC::getInstance()->set($key,$argc['value']);
}

// The caching method described above
public function set($key, $val) {
    if (apc_exists($key)) {
        apc_delete ($key);
        return apc_store($key, $val);
    }
    else 
        return false;
}


// the constructor of the configuration class. 
// It 1st looks for the configuration in
// the cache if it is not present performs the reading from the file.
public function __construct($filename = '/application/config/application.ini', 
                              $type = self::CONFIG_INI)
{
    if (defined('SYSTEM_CACHE') && SYSTEM_CACHE === 'APC'){
        $key = md5($filename);
        $cfg = APC::getInstance()->get($key);

        if (!empty($cfg)) {

            print "From Cache";

            $this->cfg = unserialize($cfg);
            return;
        } else {
            print "From File";
        }

    }
 }

我做了一些测试,MD5() 键(我在写这个问题时想到的)和 APC 本身都没有问题。我真的坚持这个,日志中没有什么奇怪的,所以如果有人能给我至少一些方向,将不胜感激。

提前致谢!

4

1 回答 1

2

问题出在我的代码中:\

public function set($key, $val) {
    /*
     *
     * If the key exists in the cache delete it and store it again,
     * but how could it exist when the else clause is like that...
     */
    if (apc_exists($key)) {
        apc_delete ($key);
        return apc_store($key, $val);
    }
    // This is very wrong in the current case
    // cuz the function will never store and the if will
    // never match..
    else 
        return false;
}

注意:始终思考并睁大眼睛,如果您仍然找不到任何东西,请从 PC 上下来并让自己休息一下。10-15 分钟后返回并提交代码。它有助于!:D

于 2013-07-16T09:07:03.680 回答