【发布时间】:2012-03-10 07:18:27
【问题描述】:
我正在尝试使用 Zend Cache 实现缓存。我使用以下代码来初始化缓存。
$tagCache = Zend_Cache::factory('Core',
'File',
array('automatic_serialization' => true),
array('cache_dir' => $cfg['instdir']. 'Cache_dir'));
$cache = Zend_Cache::factory('Capture',
'Static',
array(),
array('index_filename' => 'index',
'public_dir' => $cfg['instdir'] . 'Cached',
'tag_cache' => $tagCache));
我使用以下代码开始缓存:
$id = bin2hex($_SERVER["REQUEST_URI"]);
$cache->start($id, array());
缓存文件已生成,但我无法使用remove() 方法删除它们(缓存不刷新):
$cache->remove($id); // id generated like above from the REQUEST_URI of the page I want to refresh
我做错了什么? 谢谢。
【问题讨论】:
-
是否有任何与权限相关的错误输出到您的错误日志?您是否确认 $id 值完全相同? (对于 start() 和 remove())
-
我的日志中没有任何错误。我检查了 ids ......我什至创建了一个测试文件,其中包含一些 ids 的硬编码值。但没有运气。我已经打开了一些缓存文件,它们似乎是按应有的方式创建的……但是当我想删除它们时,什么也没有发生。缓存目录具有必要的读、写权限。
-
你是否在 remove() 调用周围包裹了一个 try/catch 块?您可能需要深入研究他们的 API 文档才能发现问题。
-
事实证明,您必须将缓存文件的路径传递给 remove 方法才能使其工作。虽然 Zend 文档说它需要一个缓存 id。无论如何,如果其他人有类似的问题......只需添加 $id = $this->_decodeId($id);到 Static.php 后端的 remove 方法。
标签: php zend-framework zend-cache