atldays / laravel-eloquent-query-cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Package info
github.com/atldays/laravel-eloquent-query-cache
pkg:composer/atldays/laravel-eloquent-query-cache
Requires
- illuminate/cache: ^10.5|^11.33|^12.0|^13.0
- illuminate/database: ^10.5|^11.33|^12.0|^13.0
- illuminate/support: ^10.5|^11.33|^12.0|^13.0
Requires (Dev)
- laravel/legacy-factories: ^1.4
- laravel/pint: ^1.21
- livewire/livewire: dev-main
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.1.1|^9|^10.0|11.x-dev
- phpunit/phpunit: ^9.5.25|^10|^11|^12
This package is auto-updated.
Last update: 2026-04-13 12:42:47 UTC
README
atldays/laravel-eloquent-query-cache is a maintained fork of the original rennokki/laravel-eloquent-query-cache package.
- Original repository: rennokki/laravel-eloquent-query-cache
- Original documentation: rennokki.gitbook.io/laravel-eloquent-query-cache
If you only need the core package behavior, use the original documentation above. This fork keeps the original package experience and adds a few improvements for modern Laravel applications and additional relationship caching scenarios.
Installation
composer require atldays/laravel-eloquent-query-cache
Use the trait on models where query caching should be available:
use Atldays\QueryCache\Traits\QueryCacheable; class Post extends Model { use QueryCacheable; }
What This Fork Adds
MorphTo caching support
The original package documentation covers the general caching API. This fork additionally supports cached morphTo relations with inherited cache configuration.
$commentable = $comment->commentable() ->cacheFor(now()->addHour()) ->cacheTags(['commentable']) ->cachePrefix('comments') ->withPlainKey() ->first();
This is useful when you want polymorphic relations to behave the same way as the rest of your cached query chains.
Cache configuration inheritance for relationships
Custom cache options can now flow more consistently into supported relationship queries.
Typical examples:
cacheFor(...)cacheTags([...])cachePrefix(...)withPlainKey()cacheDriver(...)
Custom cache repository support
In addition to passing a driver name, you can pass a cache repository instance to cacheDriver():
use Illuminate\Support\Facades\Cache; $posts = Post::query() ->cacheFor(300) ->cacheDriver(Cache::store('array')) ->get();
This is helpful when integrating the package into more customized application setups or when testing specific cache stores.
Using The Core API
The core query cache API remains aligned with the original package documentation. For the full feature set and the original behavior reference, see:
Common examples:
$posts = Post::cacheFor(3600)->get(); $post = Post::cacheFor(now()->addHour())->first(); $uncached = Post::dontCache()->get(); $tagged = Post::cacheFor(600)->cacheTags(['posts'])->get();
Testing
vendor/bin/pint --test vendor/bin/phpunit
If you run the project through Docker, the commands used in this repository are:
docker run --rm -u $(id -u):$(id -g) -v "$PWD:/app" -w /app composer:2 sh -lc 'vendor/bin/pint --test' docker run --rm -u $(id -u):$(id -g) -v "$PWD:/app" -w /app composer:2 sh -lc 'composer test'
Contributing
Please see CONTRIBUTING for details.
Security
If you discover a security issue, please open a private report with the repository maintainers instead of posting sensitive details publicly.