2012-01-05 112 views

回答

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代码。

+0

你有getTags()在这里两次,这是什么getIds()的样子,什么是两者之间的区别? – 2013-04-16 04:18:01

+0

没关系,我已经想通了,对于那些有兴趣谁,你可以看到在这里类的完整的源代码: 'http://www.tig12.net/downloads/apidocs/zf/Cache/Backend/ File.php.source.html' – 2013-04-16 08:51:12

+0

男人,这是无用的,我花了很多时间试图找出它)))。只要坚持apc – 2013-04-16 08:56:09

0

后端支持Zend\Cache\Storage\Adapter\FilesystemIterator迭代符:

$cache = $this->serviceLocator->get('yourFilesystemCacheHere'); 
$iterator = $cache->getIterator(); 
foreach($iterator as $key){ 
    echo $key; 
}