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

How works the lifetime memcache on services phalcon

Hi, i put in my phalcon project the memcache service for store a fast cache, in my services.php i put the little lifetime, but the lifetime doesnt is respected, what i did wrong in my project?


$di->set('modelsCache', function () use ($config){  

    $default = ["statsKey" => $config->application->baseUri, "persistent" => false, "host" => "", "port" => 11211];
    $frontCache = new \Phalcon\Cache\Frontend\Data(["lifetime" => 15]);
    $cache = new \Ctrle\Library\Core\Cache\MemcacheAdapter($frontCache, $default);

    return $cache;

If i do a modification in the database register, after 20 seconds i yet receive old version of cache


Have you tried setting the lifetime when you use it?

Ref: https://docs.phalcon.io/en/3.2/db-models-cache

Code from ref:

// Cache the resultset for only for 5 minutes
$products = Products::find(
        'cache' => [
            'key'      => 'my-cache',
            'lifetime' => 300,