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.

Phalcon\Cache\Exception: Cached keys need to be enabled to use this function (options['statsKey'] == '_PHCM')!

My service:

$di->set('viewCache', function() use ($config) {
    $frontCache = new Phalcon\Cache\Frontend\Igbinary(array(
        "lifetime" => $config->application->viewCacheLifeTime
    ));
    $cache = new Phalcon\Cache\Backend\Memcache($frontCache, array(
        "host" => "localhost",
        "port" => "11211",
        'persistent' => false
    ));

    return $cache;
});

volt file:

{% cache "sidebar" %}
<a>generate this content is slow so we are going to cache it </a>
{% endcache %}

Controller file:

var_dump($this->viewCache->queryKeys());
die();

Error:

Phalcon\Cache\Exception: Cached keys need to be enabled to use this function (options['statsKey'] == '_PHCM')!
phalcon/cache/backend/memcache.zep (339)
on:
var_dump($this->viewCache->queryKeys());

Whats is the error?, please help!

edited Oct '16

Add "statsKey" key option _PHCM. to options when creating memcache backend.

But keep in mind this will slow down memcache hardly.

I always disable this, and use my own Memcached methods to iterate through the keys prefixed with my custom prefix/domain.

It's not phalcon error. To query keys on memcache you need to create it with "statsKey" option with value _PHCM. Otherwise queryKeys would just return nothing - this is why there is exception. Just add these options to backend cache and that's it. But as i wrote - this will overall slow down memcache backend.

edited Oct '16

I understand there is another way for memcached is not slow?, i have ubuntu 16.04, with php 7.0 so i cant use APC because, APCU is installed... i want to cache fragments ( html code) on memory



114.4k
Accepted
answer
edited Oct '16

Yea, extend memcache backend and store in some array all saved keys which will be saved to memcache itself :D No other way.

You can use apc backend - just install apcu_bc