XML を Zend ファイルシステムのキャッシュに保存し、30 分後に有効期限が切れるようにしたいと考えています。キャッシュ期間/有効期限はどのように設定しますか? 完全な ZF2 アプリケーションのコンテキストではなく、Zend キャッシュをコンポーネントとして使用しています。
$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 ファイルのタイムスタンプは変更されません)。