donglie1898 2012-01-05 14:17
浏览 21
已采纳

使用Zend Data Cache获取命名空间中的所有键

With the Zend Data Cache - PHP API, is there a method for retrieving all keys in a namespace?

Essentially, I need to replicate what you can do with apc_cache_info, such as

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

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

It is not apparent from the documentation if this is possible.

Thanks.

  • 写回答

2条回答 默认 最新

  • doudichu1358 2012-01-27 10:10
    关注

    The Zend File Backend supports getTags() and 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());
        }
    

    In my bootstrap file i init the cache

    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); 
    

    Then in my controller i can call

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

    Suggest you check the Zend code for the specific cache backend your using.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答