cache frontend lifetime not working when using Cache

I am using phalcon 2.0.10 instead of 1.3.4. And I've found cache frontend lifetime not working when I used Cache. The cache would expire 3600 sec all the same. And it did not appear in 1.3.4.

Please post a code, which causes your problem.

edited Mar '16
    $frontCache = new \Phalcon\Cache\Frontend\Data([
        'lifetime' => 300

    $cache = new \Phalcon\Cache\Backend\Libmemcached($frontCache, [
        'servers' => [[
            'host' => '',
            'port' => '11211'
        'statsKey' => null

    $di->set('modelsCache', $cache, true);

    //use cache when query
    $ret = Model::find([
        'cache' => [
            'key' => 'foo',
            'service' => 'modelsCache'

Normally, the it will cache 300 sec. But actually, it's 3600 sec.

edited Mar '16

BackendCache in Phalcon internaly uses _lastLifetime attibute where it stores last lifetime set in start method

Your best way to go is to set lifetime internally in your find


I just want to set a public lifetime by this way. And I think the problem is caused by

And compare with this

You will know what I want.

Yeah, you are right, problem is in file

You have to submit an issue on github to fix it.

edited May '16

I hit the wall with this issue as well today.

The thing is, \Phalcon\Cache\Frontend\Data just does not respect your TTL or Lifetime flags.

If you dive into Zep code here: It's is clear that this class is half implemented.

Update - it seems that it does respect lifetime afterall! If I set it to 10 sec, it will expire and whoo-hoo re-read data again. But if I put lifetime = 86400 (1 day) it will not refresh it. I'm still digging into it to be really sure whenever this is a bug or just some gremlin from my code base / use case scenario.

edited Oct '16

Is zero for never expire?? or -1 ???