retrieved, saved, deleted). Ideal for read-heavy applications with repetitive queries (e.g., dashboards, product listings, user profiles).Cacheable) + minimal configuration (TTL, cache key naming). Compatible with Laravel 8+ (PHP 8.0+).saved/deleted events might cause cache inconsistency. Mitigation: Use transactions or locks for critical models.User::with('posts')->get())?Post should clear its User cache)?Cache::remember).Cache::tags(): Better for tag-based invalidation (e.g., user:123:posts).DB::enableQueryCache()).Product, User, DashboardMetrics).use Cacheable; to models + configure CacheEntity rules.class Product extends Model {
use Cacheable;
protected $cacheEntities = [
'default' => ['ttl' => 300, 'key' => 'product:{id}'], // 5 mins
'with_relations' => ['ttl' => 60, 'key' => 'product:{id}:with_relations']
];
}
PostDeleted clears User cache).Post::deleted(function ($post) {
Cache::forget("user:{$post->user_id}:posts");
});
CACHE_ENABLED=false) to disable caching in emergencies.Cache::get() with fallback:
$product = Cache::remember("product:{$id}", $ttl, function () use ($id) {
return Product::findOrFail($id);
});
retrieved, saved, deleted). Custom events may need manual handling.spatie/laravel-activitylog.composer require mostafaznv/laracache..env (e.g., CACHE_DRIVER=redis).User, Order).CacheEntity definitions in models.Cache::has() manually.Cache::flush() to test invalidation.KEYS, TTL, MEMORY USAGE) for debugging.How can I help you explore Laravel packages today?