我正在尝试为我今天安装的 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 本身都没有问题。我真的坚持这个,日志中没有什么奇怪的,所以如果有人能给我至少一些方向,将不胜感激。
提前致谢!