github mikebronner/laravel-model-caching 13.0.0
The Big Catch-Up -- All your issues addressed!

9 hours ago

✨ 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

  1. Update your composer.json:
    composer require mikebronner/laravel-model-caching
  2. (Optional) If you want to use the new graceful fallback feature, add to your .env:
    MODEL_CACHE_FALLBACK_TO_DB=true
  3. (Optional) Publish the updated config to get the new fallback-to-database option:
    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() or forceDelete() 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 the Cachable trait. (#528)
  • MorphTo and morphedByMany invalidation — Deleting a morphTo-related model or using attach/detach on morphedByMany relationships now correctly flushes the cache. (#575)
  • Bypass cache for pessimistic locking — Queries using lockForUpdate() or sharedLock() 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 RowValues where 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 $fillable interference — The Cachable trait no longer interferes with models that modify $fillable dynamically (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 modelsBelongsToMany relationships using custom pivot models (->using()) now correctly invalidate the cache on attach/detach/sync. (#566)
  • MorphTo eager-load cache tag resolution — Fixed cache tag generation for morphTo relationships in eager-load chains. (#579)
  • Model retrieved event on cache hit — The Eloquent retrieved event now fires correctly when results are served from cache, matching the behavior of uncached queries. (#563)
  • Missing EloquentBuilder import — Added a missing use import in CachedBuilder.php. (#558)

🧹 Housekeeping

  • Removed unnecessary Nova test fixtures and references.
  • Added SECURITY.md with 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

Don't miss a new laravel-model-caching release

NewReleases is sending notifications on new releases.