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.

$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)?

  • 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. – Walker Designs Apr 13 '16 at 0:07

You should be using craft()->cache with the 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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.