setting cache lifetime while saving is not working
http://docs.phalconphp.com/en/latest/api/Phalcon_Cache_BackendInterface.html According to api doc, I should be able to set lifetime via 3rd param while saving cache. But when I tried to store cache for 10 seconds with following code:
$di->set('dataCache', function() use ($config) { $frontend = new Phalcon\Cache\Frontend\Data(array( //'lifetime' => 10 )); $cache = new Phalcon\Cache\Backend\File($frontend, array( "cacheDir" => $config['cacheDir'] )); return $cache; });
public function indexAction() {
$dataCache = $this->di->get('dataCache');
$cacheKey = 'robots_order_id.cache';
$robots = $dataCache->get($cacheKey);
if ($robots === null)
{
$robots = new stdClass();
$this->di->get('logger')->notice('robots cache data not exists: '.date("H:i:s"));
// Store it in the cache
$dataCache->save($cacheKey, $robots, 10);
}
}
I saw that script is logging "robots cache data not exists" notice for every second. I am using ver 0.7.0
Setting the lifetime when saving the cache using the Files adapter will not work, that option is intended for adapters like Apc/Memcached that allow this.
In this case you can move the lifetime to the method get($cacheKey, 10)
I will a note to the documentation explaining this special case
I am be able to set lifetime while getting cache instead of saving as you advised. Thanks for your answer.