Repository navigation
[Feature Request] Add Tagged Cache support for the file cache driver #59719
Unanswered
charescape
asked this question in
Ideas
Replies: 1 comment 1 reply
|
@charescape I've released this drop-in replacement (strata) with cache tagging support. I share similar needs as the people from the original issue and this discussion. I have it working on my website now the way I wanted it. Give it a try and let me know if it answers your needs as well. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Description
I would like to propose adding support for Tagged Cache to the
filecache driver. Currently, as documented in the official Laravel documentation, cache tags are not supported when using thefile,dynamodb, ordatabasecache drivers. CallingCache::tags(...)with thefiledriver results in aBadMethodCallExceptionstating "This cache store does not support tagging".Background
filedriver (Illuminate\Cache\FileStore) does not extendTaggableStore, and therefore lacks any tagging capabilities.filedriver during local development or in smaller applications where setting up Redis/Memcached is unnecessary overhead. The lack of tag support forces them to either:Motivation
filedriver would improve the out-of-the-box experience, especially for local development and simpler applications.filemay not offer the same performance or atomicity as Redis/Memcached, it is still a valid persistent cache store. Providing tagging support would reduce the functional gap between drivers.erjon/laravel-cache-groups: Providescache()->groups()as a drop-in replacement for tags, working with all drivers including file and database.rodrigopedra/file-tagged-cache: A custom file driver that supports cache tags.microweber-packages/laravel-tagged-file-cache: A taggable file cache driver for Laravel.kargnas/alternative-laravel-cache: Full-featured replacements for Redis and file cache stores with proper tagging support.Proposed Implementation Approach
A file-based tagging implementation could maintain a "tag index" file (or files) that maps tags to cache keys. For example:
Cache::tags(['some-tag'])->flush()is called, the driver reads the index, retrieves all keys associated with that tag, and deletes the corresponding cache files.flock) would be required to prevent race conditions when multiple processes modify the tag index simultaneously.This is similar to how third-party packages have implemented the feature. For instance,
rodrigopedra/file-tagged-cachemaintains tag mappings and flushes associated files when tags are cleared.Potential Concerns
filedriver is inherently slower than in-memory stores. Adding tag index management may introduce additional I/O overhead, especially under high concurrency.fileadds non-trivial complexity to what is currently a very simple driver.If these concerns are deemed too significant for core inclusion, an alternative could be to officially document or recommend a blessed community package for file-based tagging.
Additional Context
dynamodbanddatabasedrivers are also currently unsupported for tagging; this issue focuses specifically on thefiledriver as a first step, but the same approach could potentially be adapted for those drivers in the future.file,dynamodb, ordatabasecache drivers".References
rodrigopedra/file-tagged-cacheerjon/laravel-cache-groupsClosing
Thank you for considering this feature request. I believe adding tagging support to the
filedriver would be a valuable enhancement to the Laravel caching system, improving the developer experience for a large segment of the community.All reactions