Lumen Cache Tagging Integration with Illuminate Cache: Missing Service Provider Registration
0 reputation · 23 Aug 2022, 10:42 UTC
0 reputation · 23 Aug 2022, 10:42 UTC
Lumen reuses Laravel's Illuminate\Cache\CacheManager and CacheRepository classes, providing the same drivers (file, database, redis, memcached). However, Lumen's default service provider stack omits the CacheTaggingServiceProvider that enables the Cache::tags() fluent interface in Laravel.
A team adopting Lumen wants to use cache tags for granular invalidation across related data sets—exactly as documented for Laravel. The constraint is that Lumen does not register the tagging provider by default, and the documentation does not prescribe whether to add it manually, implement a custom provider, or avoid tags entirely and rely on key-based flushing. Without the provider, calls to Cache::tags('group')->put(...) either throw an exception or silently fall back to untagged storage, producing stale data when tag-based invalidation is expected.
CacheTaggingServiceProvider, creating a minimal custom provider, or using a third-party package?CacheServiceProvider) that affect tag registration?35275 reputation · 23 Aug 2022, 11:31 UTC
Register Laravel’s Illuminate\Cache\CacheTaggingServiceProvider in bootstrap/app.php after the existing CacheServiceProvider. This makes the Cache::tags() fluent interface available in Lumen.
Likely explanation: Lumen’s minimal provider list omits the tagging provider, so the tagging layer is never attached to the cache manager.
Confirmed facts (from Laravel/Lumen source):
CacheTaggingServiceProvider adds the tagging extension to the cache manager.CacheServiceProvider.bootstrap/app.php.$app->register(App\Providers\CacheServiceProvider::class); (or the framework’s default) is present.$app->register(Illuminate\Cache\CacheTaggingServiceProvider::class);
php -S localhost:8000 -t public).php artisan tinker and executing:
Cache::tags('group')->put('key', 'value', 60);
Cache::tags('group')->get('key');
If the driver supports tags, the value returns; with the file driver the call succeeds but the entry is stored without tag metadata.To confirm whether tagging will have any effect, please specify which cache driver you are configured to use (check config/cache.php or the CACHE_DRIVER env var). If you are using the file driver, tagging will be a no‑op and you should switch to a supported driver (Redis, database, or DynamoDB) for tag‑based invalidation to work.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.