title: How do I set expire time for Zend Cache Storage?
body: <p>I would like to store some XML in a Zend filesystem cache and have it expire after 30 minutes. How does one set the cache duration / expiry? I am using Zend cache as a component and not in the context of a full ZF2 application.</p>
  
  <pre><code>$cache   = \Zend\Cache\StorageFactory::factory(array(
      'adapter' =&gt; array(
          'name' =&gt; 'filesystem',
          'ttl' =&gt; 60, // kept short during testing
          'options' =&gt; array('cache_dir' =&gt; __DIR__.'/cache'),
      ),
      'plugins' =&gt; array(
          // Don't throw exceptions on cache errors
          'exception_handler' =&gt; array(
              'throw_exceptions' =&gt; false
          ),
      )
  ));
  $key    = 'spektrix-events';   
  $events = new SimpleXMLELement($cache-&gt;getItem($key, $success));
  
  if (!$success) {
      $response = $client-&gt;setMethod('GET')-&gt;send();
      $events = new SimpleXMLElement($response-&gt;getContent());
      $cache-&gt;setItem('spektrix-events', $events-&gt;asXML());
  }
  
  
  var_dump($cache-&gt;getMetadata($key)); // the mtime on the file stays the same as does timestamp from ls -al in a terminal.
  </code></pre>
  
  <p>How do I set an expiration time and then subsequently check if the cache has expired? The above code does not seem to expire the cache after 60 seconds (the .dat file's timestamp does not change)</p>