<p>Looks like a bug in the plugin.</p>

<p>The 3rd <code>$expire</code> parameter when calling set <a href="https://craftcms.com/classreference/etc/cache/FileCache#set-detail" rel="nofollow noreferrer">states</a>:</p>

<blockquote>
  <p>The number of seconds in which the cached value will expire. 0 means never expire.</p>
</blockquote>

<p>But it's passing in the PHP time format notation.  I'd suggest contacting the author of the plugin.</p>

CC BY-SA 3.0
2016-12-15T03:20:55.870Z
2016-12-15T03:20:55.870Z
Brad Bell
<p>My cache won't expire. This is effectively my code:</p>

<pre><code>    $template = (isset($params['template']) ? $params['template'].'?'.$config['pageParam'].'='.$pageParam : null);

    if(craft()-&gt;cache-&gt;get($template))
    {
        echo craft()-&gt;cache-&gt;get($template);
        craft()-&gt;end();
    }

    if(craft()-&gt;config-&gt;get('enableTemplateCaching'))
    {
        craft()-&gt;cache-&gt;set($template, $JsonValue, 'P1D');
    }
</code></pre>

<p>The cache saves just fine but when I forward the clock on my server a few days ahead and refresh the page it's still using the cached data. I've also tried actually waiting a few days in case it was using another clock but that didn't help either. </p>

<p>Is there something I'm missing? I figure Craft or the Yii Framework will take care of expiring the cache after the one day period set (P1D). I don't see any methods to check the date of the cache or anything where I could manually intervene.</p>

<p>For what it's worth I'm using <a href="https://github.com/theolampert/ElementAPI" rel="nofollow noreferrer">theolampert's fork</a> of the ElementAPI plugin which adds caching.</p>

<plugin-development><cache><plugin-elementapi>
Data cached in plugin controller via CacheService won't expire
# Data cached in plugin controller via CacheService won't expire

(Asked by: username_0 on 2016-12-14)

My cache won't expire. This is effectively my code:
    $template = (isset($params['template']) ? $params['template'].'?'.$config['pageParam'].'='.$pageParam : null);

    if(craft()->cache->get($template))
    {
        echo craft()->cache->get($template);
        craft()->end();
    }

    if(craft()->config->get('enableTemplateCaching'))
    {
        craft()->cache->set($template, $JsonValue, 'P1D');
    }

The cache saves just fine but when I forward the clock on my server a few days ahead and refresh the page it's still using the cached data. I've also tried actually waiting a few days in case it was using another clock but that didn't help either. 
Is there something I'm missing? I figure Craft or the Yii Framework will take care of expiring the cache after the one day period set (P1D). I don't see any methods to check the date of the cache or anything where I could manually intervene.
For what it's worth I'm using theolampert's fork of the ElementAPI plugin which adds caching.

**Tags:** plugin-development, cache, plugin-elementapi

---

## 1 answers

### Answer by username_1 on 2016-12-15. Score: 1 | Accepted answer

Looks like a bug in the plugin.

The 3rd `$expire` parameter when calling set [states](https://craftcms.com/classreference/etc/cache/FileCache#set-detail):

> The number of seconds in which the cached value will expire. 0 means never expire.

But it's passing in the PHP time format notation. I'd suggest contacting the author of the plugin.


---

