<p>Yeah, it's slightly awkward.</p>

<p>First off it should be <code>'0'</code>, instead of <code>false</code> if you want it to cache indefinitely (documentation bug, just fixed).</p>

<p>It's slightly awkward because the <code>cacheDuration</code> config setting is used for multiple things, but when the <code>TemplateCacheService</code> uses it, it requires an expiration date (not optional).</p>

<p>So if it sees <code>0</code>, it will just pick one reasonably far out (a year), but you can set it to something higher if you want.</p>

<p>What should probably happen is everywhere that uses the <code>cacheDuration</code> config setting should have its own, separate config setting.</p>

<p>Not going to happen for Craft 2, but make a note to look at it once Craft 3 launches.</p>

CC BY-SA 3.0
2017-01-20T02:33:59.397Z
2017-01-20T02:33:59.397Z
Brad Bell
<p>So I noticed that by setting the <code>'cacheDuration' =&gt; false</code> it seems to set, by default, the expiration date to 1 year from when the cache is saved. </p>

<p>I found this in <code>/app/services/TemplateCacheService.php</code> starting from line 263:</p>

<pre><code>if($duration &lt;= 0) 
{
  $duration = 31536000; // 1 year
}
</code></pre>

<p>I know a longer duration could be achieved by setting the expiration to something like <code>4Y</code>. But I wanted to raise this and ask if it was an oversight or what the reason was for setting it to a year and overriding the specific value of not setting an expiration at all...?</p>

<p>Thanks.</p>

<cache>
'cacheDuration' => false, sets cache file expiration date to 1 year
# 'cacheDuration' => false, sets cache file expiration date to 1 year

(Asked by: username_0 on 2017-01-19)

So I noticed that by setting the 'cacheDuration' => false it seems to set, by default, the expiration date to 1 year from when the cache is saved. 
I found this in /app/services/TemplateCacheService.php starting from line 263:
if($duration <= 0) 
{
  $duration = 31536000; // 1 year
}

I know a longer duration could be achieved by setting the expiration to something like 4Y. But I wanted to raise this and ask if it was an oversight or what the reason was for setting it to a year and overriding the specific value of not setting an expiration at all...?
Thanks.

**Tags:** cache


---

## 1 answers

### Answer by username_1 on 2017-01-20. Score: 3 | Accepted answer

Yeah, it's slightly awkward.

First off it should be `'0'`, instead of `false` if you want it to cache indefinitely (documentation bug, just fixed).

It's slightly awkward because the `cacheDuration` config setting is used for multiple things, but when the `TemplateCacheService` uses it, it requires an expiration date (not optional).

So if it sees `0`, it will just pick one reasonably far out (a year), but you can set it to something higher if you want.

What should probably happen is everywhere that uses the `cacheDuration` config setting should have its own, separate config setting.

Not going to happen for Craft 2, but make a note to look at it once Craft 3 launches.


---

