2

我正在尝试使用 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

我究竟做错了什么 ?谢谢。

4

1 回答 1

2

$cache->remove()是后端remove()方法的代理。在这种情况下,您正在使用Static后端,因此我们会在那里查看发生了什么。

我对该方法的阅读使我相信$id参数 toremove必须是文件名,因此:

$cache->remove('index'); 

将工作。

清除缓存的更常用方法是使用该clean()方法。请参阅手册

于 2012-03-14T10:06:40.543 回答