✨ Highlights
This release adds Laravel 13 support, introduces several powerful new features — including a ModelCache Facade, graceful fallback when the cache backend is down, and smarter cache invalidation — and fixes a batch of edge-case bugs.
⬆️ Upgrade Steps
- Update your
composer.json:composer require mikebronner/laravel-model-caching
- (Optional) If you want to use the new graceful fallback feature, add to your
.env:MODEL_CACHE_FALLBACK_TO_DB=true
- (Optional) Publish the updated config to get the new
fallback-to-databaseoption:php artisan modelCache:publish --config
⚠️ Breaking Changes
Laravel 10 dropped — Minimum Laravel version is now 11. If you are still on Laravel 10, stay on v12.x.
PHP 8.1 dropped — Minimum PHP version is now 8.2. If you are still on PHP 8.1, stay on v12.x.
Existing applications on Laravel 11 or 12 with PHP 8.2+ should be able to upgrade without any code changes.
🚀 New Features
- Laravel 13 support — Bumped all
illuminate/*dependencies to accept^13.0. (#557) - ModelCache Facade — New
ModelCache::invalidate()Facade for programmatic cache flushing without Artisan commands. Accepts a single model class or an array. (#571) - Graceful fallback to database — When enabled via
MODEL_CACHE_FALLBACK_TO_DB=true, the package logs a warning and falls back to direct database queries if the cache backend (e.g. Redis) is unavailable, instead of throwing an exception. (#574) - Cache tags for joined tables — Queries using
join(),leftJoin(), etc. now generate cache tags for the joined tables, so writes to joined models correctly invalidate the cache. (#577) - Smarter delete/forceDelete invalidation — Cache is now only flushed when
delete()orforceDelete()actually removes records (affected rows > 0), avoiding unnecessary invalidation on no-op deletes. (#578) - Custom Eloquent builder support — Models that define a custom
newEloquentBuilder()method now work correctly with theCachabletrait. (#528) - MorphTo and morphedByMany invalidation — Deleting a morphTo-related model or using
attach/detachonmorphedByManyrelationships now correctly flushes the cache. (#575) - Bypass cache for pessimistic locking — Queries using
lockForUpdate()orsharedLock()now automatically bypass the cache, since locked queries should always hit the database. (#573)
🐛 Bug Fixes
belongsToMany()->sync()memory exhaustion — Fixed a memory leak when syncing large pivot datasets. (#569)- Cursor pagination crash — Fixed
RowValueswhere type breaking compatibility with Laravel's cursor pagination. (#562) - Multi-domain paginator base URL — Paginated results now use the correct base URL per domain in multi-domain applications. (#561)
- UUID validation crash in cache keys — Fixed a crash when building cache keys containing non-UUID binary strings. (#559)
- Dynamic
$fillableinterference — TheCachabletrait no longer interferes with models that modify$fillabledynamically (e.g. in__construct()). (#564) - Pivot model observer events — Custom pivot model observers now fire correctly on cached models. (#567)
- Pivot cache invalidation with custom models —
BelongsToManyrelationships using custom pivot models (->using()) now correctly invalidate the cache onattach/detach/sync. (#566) - MorphTo eager-load cache tag resolution — Fixed cache tag generation for
morphTorelationships in eager-load chains. (#579) - Model
retrievedevent on cache hit — The Eloquentretrievedevent now fires correctly when results are served from cache, matching the behavior of uncached queries. (#563) - Missing
EloquentBuilderimport — Added a missinguseimport inCachedBuilder.php. (#558)
🧹 Housekeeping
- Removed unnecessary Nova test fixtures and references.
- Added
SECURITY.mdwith vulnerability reporting instructions. - Added Dependabot configuration for automated dependency updates.
- Comprehensive README overhaul with badges, table of contents, before/after examples, driver comparison table, and real-world usage examples.
🧪 Testing
- 335+ integration tests across PHP 8.2–8.5 and Laravel 11–13.
- New test coverage for:
reorder()caching, delete/forceDelete flush behavior, custom builders, dynamic fillable, lock queries, cursor pagination, MorphTo eager loads, multi-domain pagination, and pivot model observers.
Full Changelog: 12.0.4...13.0.0