0

今日 APC をインストールしたアプリケーションの構成パーサーを構築しようとしていますが、シリアル化されたオブジェクトをストアに入れようとするたびに、ストアに入れられません。(PHP 5.3.16 [私の開発環境] で私のバージョン [3.1.8-dev] を apc.php でチェックしているので、データがキャッシュにないことは確かです)。これは、データをキャッシャーに渡す方法です。

// 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 に答える