0

這裏是我的緩存初始化代碼:獲取所有緩存鍵中的Zend數據緩存

use Zend\Cache\StorageFactory; 
$cache = StorageFactory::factory(array(
        'adapter' => array(
          'name' => 'filesystem', 
          // With a namespace we can indicate the same type of items 
          // -> So we can simple use the db id as cache key 
          'options' => array(
            'namespace' => 'dbtable', 
            'cache_dir' => Pluto::path('cache') 
          ), 
        ), 
        'plugins' => array(
          // Don't throw exceptions on cache errors 
          'exception_handler' => array(
            'throw_exceptions' => false 
          ), 
          // We store database rows on filesystem so we need to serialize them 
          'Serializer' 
        ) 
      )); 

什麼我想知道是我如何獲得所有我們有這個緩存對象內部的緩存鍵的

例如,執行現在此代碼:

$cache->setItem('key1','foo'); 

$cache->setItem('key2','bar'); 

$cache->setItem('key3','baz'); 

並在不同區域/點執行此代碼:

$cache->setItem('key4','foo2'); 

$cache->setItem('key5','bar2'); 

$cache->setItem('key6','baz2'); 

我想含有['key1','key2','key3','key4','key5','key6']陣列這將從高速緩存對象(包括該特定請求過程中並沒有受到影響的)內的所有鍵的內部數組來presumbly?

回答

0

AFAIK,從zend-cache沒有方法檢索緩存對象內的所有密鑰。但是如果你想檢索所有的鍵,你可以迭代對象。這不是array,但是如果你願意的話,你可以把它設爲array

$caches = $cache->getIterator(); 
$cacheKeys = [] 
foreach ($caches as $key) { 
    // $key is the cache key 
    $cacheKeys[] = $key; 
} 

print_r($cacheKeys); 
+0

@jkushner,請注意此答案如果是幫助 –