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.
$frontCache = new \Phalcon\Cache\Frontend\Data([ 'lifetime' => 300 ]); //backend $cache = new \Phalcon\Cache\Backend\Libmemcached($frontCache, [ 'servers' => [[ 'host' => '127.0.0.1', '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.
BackendCache in Phalcon internaly uses _lastLifetime attibute where it stores last lifetime set in start method
I just want to set a public lifetime by this way. And I think the problem is caused by https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/query.zep#L3268
And compare with this https://github.com/phalcon/cphalcon/blob/1.3.4/ext/mvc/model/query.c#L4775
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.
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: https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/frontend/data.zep#L63 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.