Answers.Body: <p>You should be using <code>craft()-&gt;cache</code> with the <a href="https://craftcms.com/docs/config-settings#cacheMethod" rel="nofollow">cacheMethod</a> config setting set to <code>file</code> (which it is by default) instead of <code>craft()-&gt;fileCache</code>.  The latter is deprecated and won't work in Craft 3.</p>
  
  <p>Yii does have <a href="https://github.com/yiisoft/yii/blob/1.1.17/framework/caching/CFileCache.php#L101" rel="nofollow">garbage collection</a> on cache, and by default an item has a 0.01% change of being purged from cache regardless of expiry time.</p>
  
  <p>If you think you're not being garbage collected, you can check the file modified time of the files in <code>craft/storage/runtime/cache</code>.  If you explicitly pass in <code>0</code> as an expiration time, Yii will set the file's modification date to a <a href="https://github.com/yiisoft/yii/blob/1.1.17/framework/caching/CFileCache.php#L157" rel="nofollow">year out</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-11T18:41:24.977Z
Answers.LastActivityDate: 2016-04-11T18:41:24.977Z
Answers.UserDisplayName: Brad Bell
Body: <p>I am using the fileCache command in a custom plugin. I've set it to never expire so that I can provide a special link to our client to force a refresh.</p>
  
  <p>Problem is, the cache seems to be killing itself off. On one day I can see record of it regenerating three separate times, so it is </p>
  
  <pre><code>$craft-&gt;fileCache-&gt;add($cacheKey, $dataToAddToCache, $cacheExpire);
  $craft-&gt;fileCache-&gt;add('my-hardcoded-key', 'string of data', 0);
  </code></pre>
  
  <p>So basically I am doing this.</p>
  
  <pre><code>if (NEED_TO_REGEN) {
     $craft-&gt;fileCache-&gt;delete($cacheKey);
  }
  $a_cacheVal = $craft-&gt;fileCache-&gt;get($cacheKey);
  if (empty($a_cacheVal)) {
      //use the cached data
  } else {
     $craft-&gt;fileCache-&gt;add($cacheKey, $dataToAddToCache, $cacheExpire);
  }
  </code></pre>
  
  <p>Does admin modification of resources affect fileCache at all (updating an entry wouldn't kill of my plugin fileCache would it?) The admins is not doing a full Clear Cache inside settings or anything. So why would this particular cache be regenerating frequently (multiple times per day in some case)?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-13T00:07:49.207Z
Comments.Text: Thanks. I've changed from craft()->fileCache to craft()->cache. I can verify the date modified on the file is one year out so the "0" must be working as expected. I doubt garbage collection is the issue because the site has no where near enough traffic to have that happen as frequently as I'm seeing it.
Comments.UserDisplayName: Walker Designs
Tags: <filecache>
Title: fileCache seems to expire even though I have it set to 0
ThreadText: # fileCache seems to expire even though I have it set to 0
  
  (Asked by: username_0 on 2016-04-11)
  
  I am using the fileCache command in a custom plugin. I've set it to never expire so that I can provide a special link to our client to force a refresh.
  
  Problem is, the cache seems to be killing itself off. On one day I can see record of it regenerating three separate times, so it is
  
  ```
  $craft->fileCache->add($cacheKey, $dataToAddToCache, $cacheExpire);
  $craft->fileCache->add('my-hardcoded-key', 'string of data', 0);
  
  ```
  
  So basically I am doing this.
  
  ```
  if (NEED_TO_REGEN) {
     $craft->fileCache->delete($cacheKey);
  }
  $a_cacheVal = $craft->fileCache->get($cacheKey);
  if (empty($a_cacheVal)) {
      //use the cached data
  } else {
     $craft->fileCache->add($cacheKey, $dataToAddToCache, $cacheExpire);
  }
  
  ```
  
  Does admin modification of resources affect fileCache at all (updating an entry wouldn't kill of my plugin fileCache would it?) The admins is not doing a full Clear Cache inside settings or anything. So why would this particular cache be regenerating frequently (multiple times per day in some case)?
  
  **Tags:** filecache
  
  > **Comments:**
  > **username_0**: Thanks. I've changed from craft()->fileCache to craft()->cache. I can verify the date modified on the file is one year out so the "0" must be working as expected. I doubt garbage collection is the issue because the site has no where near enough traffic to have that happen as frequently as I'm seeing it.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-04-11. Score: 1 | Accepted answer
  
  You should be using `craft()->cache` with the [cacheMethod](https://craftcms.com/docs/config-settings#cacheMethod) config setting set to `file` (which it is by default) instead of `craft()->fileCache`. The latter is deprecated and won't work in Craft 3.
  
  Yii does have [garbage collection](https://github.com/yiisoft/yii/blob/1.1.17/framework/caching/CFileCache.php#L101) on cache, and by default an item has a 0.01% change of being purged from cache regardless of expiry time.
  
  If you think you're not being garbage collected, you can check the file modified time of the files in `craft/storage/runtime/cache`. If you explicitly pass in `0` as an expiration time, Yii will set the file's modification date to a [year out](https://github.com/yiisoft/yii/blob/1.1.17/framework/caching/CFileCache.php#L157).
  
  
  ---
  
  