我想在 Zend 文件系统缓存中存储一些 XML,并让它在 30 分钟后过期。如何设置缓存持续时间/到期时间?我使用 Zend 缓存作为一个组件,而不是在完整的 ZF2 应用程序的上下文中。
$cache = \Zend\Cache\StorageFactory::factory(array(
'adapter' => array(
'name' => 'filesystem',
'ttl' => 60, // kept short during testing
'options' => array('cache_dir' => __DIR__.'/cache'),
),
'plugins' => array(
// Don't throw exceptions on cache errors
'exception_handler' => array(
'throw_exceptions' => false
),
)
));
$key = 'spektrix-events';
$events = new SimpleXMLELement($cache->getItem($key, $success));
if (!$success) {
$response = $client->setMethod('GET')->send();
$events = new SimpleXMLElement($response->getContent());
$cache->setItem('spektrix-events', $events->asXML());
}
var_dump($cache->getMetadata($key)); // the mtime on the file stays the same as does timestamp from ls -al in a terminal.
如何设置过期时间,然后检查缓存是否已过期?上面的代码似乎没有在 60 秒后过期缓存(.dat 文件的时间戳没有改变)