Framework: [Question/Proposal] File Cache Driver Tags

Created on 18 Mar 2014  路  11Comments  路  Source: laravel/framework

Will the file cache driver ever be receiving any kind of tag support? I appreciate the performance of this may be pretty poor, but it'd be a pretty cool feature for low traffic sites. Does anyone know of this already existing in a package? I appreciate it may not something you may not want in the core @taylorotwell.

Most helpful comment

For those whom may be interested I developed this package to provide a taggable file cache.

https://github.com/unikent/taggedFileCache

The task of clearing up flushed tags is queued as a job so can be offset to a worker process to mitigate performance impact.

All 11 comments

I've always wondered this. Can you explain why this is not suitable for the file cache driver? What exactly are the performance issues?

:+1:

How would it be implemented?

I only had a quick look at how the Cache Tags work, but I guess it works by creating a namespace, based on the passed tags. When one of the tags is flushed, to data isn't removed, but the namespace changes, so every combination which includes that tag cannot be accessed, so will store a fresh object.
APC/memcached etc will automatically purge old records, but the file and database don't. That doesn't really matter for normal cache objects, because they just get overridden (because the key is the same), but when the namespace changes, those objects are kind of lost and will remain there forever (until manually cleared).
And because the application doesn't track which tag combinations are active or when a file is accessed last, you don't know what can be deleted and what is still used..
So you would either have a ever growing cache, or you have to manually clear the cache every once in a while, thus defeating a part of the problem of the cache tags in the first place.. I'm guessing that that's the problem?

Edit: But I guess, when the TagSet just creates a namespace, you could use this namespace to place all the tagged objects in a specific subdirectory, and delete that subdirectory when flushing a certain TagSet. But this would only work when you explicitly delete the same tags as used for setting, so when you use the example from http://laravel.com/docs/cache#cache-tags, flushing only 'authors', wouldn't delete the 'people,authors' dir, only force to refresh them but leave the objects somewhere abandoned in the cache dir..

See above.

I didn't say it would be easy.

Instead of putting the actual cache files (or copies of them) into a 'tag' namespaced subdirectory you could just create a tags directory with each file containing a list of the cached files included within that tag. Tagging a cache item just adds to that array. Then when flushing the cache you loop over the array and invalidate those cache keys. Using the example from the docs the filesystem would look like this. Obviously the filenames wouldn't be the exact keys.

/cache/tags/people

return [
    'John',
    'Anne',
];

/cache/tags/artists

return [
    'John',
];

/cache/tags/authors

return [
    'Anne',
];

/cache/John
/cache/Anne

Hello, will this be done at some point?

I found this package https://github.com/artdevue/Fcache

But its not working well

Hi, sorry for commenting this old issue.

But I found that RedisTaggedCache has solved the ever-growing problem that @barryvdh mentioned by deleteForeverKeys().

So, can we implement this solution to file & database?

+1

For those whom may be interested I developed this package to provide a taggable file cache.

https://github.com/unikent/taggedFileCache

The task of clearing up flushed tags is queued as a job so can be offset to a worker process to mitigate performance impact.

Was this page helpful?
0 / 5 - 0 ratings