我正试图为我的应用程序构建一个配置解析器,我今天安装了APC,但每次我试图将序列化对象放入存储区时,它都不会进入,也不会。(我正在用apc.php检查我在php 5.3.16[my dev Environment]上的[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本身都没有问题。我真的被这件事卡住了,日志里没有什么奇怪的,所以如果有人能给我一些指导,我将不胜感激。
提前感谢!
问题出现在我的代码中:''
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;
}
注意:如果你仍然找不到任何东西,一定要思考并睁大眼睛,离开电脑休息一下。10-15分钟后回来,打开代码。它有帮助!:D