以下是我的缓存初始化代码:
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']的数组,该数组应该来自缓存对象(包括在此特定请求期间未受影响的键)内所有键的内部数组。
发布于 2017-07-24 07:46:51
AFAIK,没有从zend-cache检索缓存对象中所有键的方法。但是如果你想检索所有的键,你可以迭代这个对象。它不是array,但如果您愿意,可以将它作为array。
$caches = $cache->getIterator();
$cacheKeys = []
foreach ($caches as $key) {
// $key is the cache key
$cacheKeys[] = $key;
}
print_r($cacheKeys);https://stackoverflow.com/questions/45271776
复制相似问题