Laravel Cache Helper Package
Published on by Paul Redmond
The laravel-cache package by Andrey Helldar provides a helper for working with cache in Laravel. Using the key()
method, you can generate a cache instance to get, set, update, and remove cache values:
use DragonCode\Cache\Services\Cache; // Default is one day; you can pass a custom TTL for cache duration with the ->ttl() method.$cache = Cache::make()->key('foo', 'bar', ['baz', 'baq']); $cache->put(static fn() => 'Some value');$cache->get();$cache->has();$cache->forget();
This package also supports tagging for repositories that support it, which you can use by calling the tags()
method:
use DragonCode\Cache\Services\Cache; $cache = Cache::make() ->tags('actor', 'author') ->key('foo', 'bar', ['baz', 'baq']); $cache->get();$cache->has();// etc.
You can retrieve tagged cache items using the same tags provided:
use DragonCode\Cache\Services\Cache; $cache = Cache::make()->key('foo', 'bar'); // Contains cached `Some value`$cache->tags('actor', 'author')->put(static fn() => 'Some value'); // Returns cached `Some value`$cache->tags('actor', 'author')->get(); $cache->tags('actor')->get(); // returns `null`$cache->tags('author')->get(); // returns `null`
You can learn more about this package, get full installation instructions, and view the source code on GitHub.