2

使用Zend Data Cache - PHP API,是否有一种方法可以检索命名空间中的所有键?

本质上,我需要复制您可以使用apc_cache_info执行的操作,例如

$info = apc_cache_info("user");
$keys = array();

foreach ($info["cache_list"] as $entry) {
    $keys[] = $entry["info"];
}

从文档中看不出这是否可行。

谢谢。

4

2 回答 2

1

Zend 文件后端支持 getTags() 和 getIds()

class Zend_Cache_Backend_File
{
    ....
    /**
     * Return an array of stored tags
     *
     * @return array array of stored tags (string)
     */
    public function getTags()
    {
        return $this->_get($this->_options['cache_dir'], 'tags', array());
    }
    /**
     * Return an array of stored tags
     *
     * @return array array of stored tags (string)
     */
    public function getTags()
    {
        return $this->_get($this->_options['cache_dir'], 'tags', array());
    }

在我的引导文件中,我初始化缓存

protected function _initCache()
{
    $frontendOptions = array(
        'lifetime' => 3600*24*5, // cache lifetime of 5 days
        'automatic_serialization' => true,
        'logging' => false,
        'caching' => true
    );

    $backendOptions = array(
        'cache_dir' => './../data/cache/', // Directory where to put the cache files
        'hashed_directory_level' => 2
    );

    // getting a Zend_Cache_Core object
    $cache = Zend_Cache::factory(
        'Core',
        'File',
        $frontendOptions,
        $backendOptions);
    Zend_Registry::set('cache', $cache); 

然后在我的控制器中我可以调用

public function indexAction()
{
    $cache = Zend_Registry::get('cache');
    Zend_Debug::dump($cache->getTags());
    Zend_Debug::dump($cache->getIds());

建议您检查您使用的特定缓存后端的 Zend 代码。

于 2012-01-27T10:10:16.197 回答
0

后端支持Zend\Cache\Storage\Adapter\FilesystemIteratorInterator:

$cache = $this->serviceLocator->get('yourFilesystemCacheHere');
$iterator = $cache->getIterator();
foreach($iterator as $key){
   echo $key;
}
于 2016-09-11T17:04:03.223 回答