How do I set expire time for Zend Cache Storage?

萝らか妹 提交于 2019-12-04 09:54:03

Have you tried to set option ttl in adapter options?

'adapter' => array(
    'name' => 'filesystem',
    'options' => array(
        'cache_dir' => __DIR__.'/cache',
        'ttl' => 3600,
    ),
),

ZF documentation has even nice quick start examples, where TTL is presented.

Update:

I have tested next script, and TTL is working like it should. You have problem elsewhere.

$cache = Zend\Cache\StorageFactory::factory(array(
    'adapter' => array(
        'name'    => 'filesystem',
        'options' => array('ttl' => 5),
    ),
));

$cache->setItem('a', 'b');
for ($i = 1; $i <= 7; $i++) {
    sleep(1);
    echo "var_dump on {$i}th second ... ";
    var_dump($cache->getItem('a'));
}

Output is :

var_dump on 1th second ... string(1) "b"
var_dump on 2th second ... string(1) "b"
var_dump on 3th second ... string(1) "b"
var_dump on 4th second ... string(1) "b"
var_dump on 5th second ... NULL
var_dump on 6th second ... NULL
var_dump on 7th second ... NULL
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!