2012-01-05 67 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; 
} 
相關問題