We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 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?

services.php

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

    $default = ["statsKey" => $config->application->baseUri, "persistent" => false, "host" => "127.0.0.1", "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



1.3k

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,
        ],
    ]
);