We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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

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