Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Cacheable

Laravel Cacheable Laravel Package

kjmtrue/laravel-cacheable

kjmtrue/laravel-cacheable adds simple, automatic caching to your Eloquent models, storing query results and clearing them when records change. Cut repeated database hits, speed up busy Laravel apps, and keep data fresh with minimal code and sensible defaults.

View on GitHub
Deep Wiki
Context7

Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.

Frequently asked questions about Laravel Cacheable
How do I install kjmtrue/laravel-cacheable in a Laravel app?
Install it with Composer by running composer require kjmtrue/laravel-cacheable. Laravel's package auto-discovery registers the service provider, so manual registration is usually unnecessary. Publish the package configuration if you want to change the default cache store or TTL. Then add the cacheable behaviour to the Eloquent models you want covered.
Which Laravel and PHP versions does kjmtrue/laravel-cacheable support?
The package targets modern Laravel releases that support Eloquent model events and the standard cache repository. Check the composer.json constraints on Packagist before installing to confirm your Laravel and PHP versions match. If you are on an older release, pin a compatible version or test on a staging branch first.
How does the cache get cleared when a model record changes?
The package hooks into Eloquent model events such as saved, updated, deleted, and restored, and flushes the cache entries associated with that model. Because it works at the model layer rather than in your controllers, writes made anywhere in the application trigger invalidation. That keeps cached query results fresh without you writing manual forget calls.
Do I need to configure a cache driver for it to work?
It uses whatever cache store your Laravel application is already configured with, so no separate driver setup is required. In production you will normally want Redis or Memcached for shared, fast storage, while file or array stores are fine for local development. The array driver only lives for a single request, so avoid it in production.
Can I disable caching for specific models or queries?
Caching is opt-in per model, so any model that does not use the package's trait keeps hitting the database as normal. Within a cacheable model you can also bypass the cache for a particular query or temporarily turn caching off when you need guaranteed fresh reads. Check the package documentation for the exact methods, since they follow the Rinvex Cacheable API.
Does it cache relationship queries like hasMany or belongsTo?
Eager-loaded relationships benefit when the parent query itself is cached by the package. Direct lazy-loaded relationship queries on a cacheable model can also be covered, but you should test your specific access patterns. Relationship queries that change very frequently gain less from caching and may be better left uncached.
How is this different from using Cache::remember manually?
Cache::remember makes you hand-write cache keys and remember to forget them on every write, which is easy to get wrong. This package centralises that logic on the model, so key generation and invalidation happen automatically. The trade-off is less fine-grained control per query, though you can still drop down to the cache facade for special cases.
How do I test models that use cacheable caching?
Use the array cache driver in your test environment so cached data stays isolated per test and is discarded with the application. Call Cache::flush() or refresh the app between tests if you reuse the same store. Add a test that updates a record and asserts the next read reflects the change, which verifies invalidation end to end.
What should I watch out for when running this in production?
Choose a shared cache store such as Redis so every app server sees the same cached data. Watch memory usage and set sensible TTLs, since unbounded key growth is the usual pitfall. Also confirm invalidation for bulk updates and raw SQL writes, which may bypass Eloquent events and leave stale entries behind.
Is kjmtrue/laravel-cacheable actively maintained and does it work with recent Laravel versions?
It is a fork of the well-known Rinvex Cacheable package, so the API and behaviour should feel familiar to developers who have used that library. Check the GitHub repository for recent commits, open issues, and the Laravel constraint in composer.json before adopting it. Because it is a smaller fork, pinning a version and skimming the source is a sensible precaution.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo