We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Get a list of all cached keys from APC

I'm writing an app that uses the \Phalcon\Cache\Backend\Apc cache class.

I currently need to get a list of all cached keys, is there a way I can do this with Phalcon without using the built in ApcIterator class or apc_cache_info method? This is due to the fact that I might switch from cache methods later on as the hosting server might not support APC.

Thank you



77.7k
Accepted
answer
edited Jun '16

I think you're looking for this: https://docs.phalcon.io/en/latest/reference/cache.html#querying-the-cache

// Query all keys used in the cache
$keys = $cache->queryKeys();
foreach ($keys as $key) {
    $data = $cache->get($key);
    echo "Key=", $key, " Data=", $data;
}

// Query keys in the cache that begins with "my-prefix"
$keys = $cache->queryKeys("my-prefix");