elipzis/laravel-cacheable-model
get(), first(), and other query results. This aligns well with read-heavy applications (e.g., dashboards, product listings) where repetitive queries dominate.Cacheable), enabling selective optimization without global overhead. This avoids the pitfall of blindly caching all models (e.g., frequently updated entities like User or Order).insert, update, or delete operations, leveraging Laravel’s event system. This mitigates stale data risks but requires careful TTL configuration.whereIn, join). However, the package’s query normalization may not cover all edge cases (e.g., raw SQL expressions).withoutCache()) is provided for edge cases.where clauses with expressions) may not generate unique keys, leading to stale data. Testing with production-like queries is essential.Product, Post vs. UserSession).get() calls vs. 50% dynamic where queries).Model::update([...])) handle cache invalidation?where clauses) be validated?ProductCategory, BlogPost) to validate performance and cache hit ratios.withoutCache() for critical paths during testing.Cacheable trait to models with stable read patterns.Product vs. 1-minute for Promotion).product:123 and inventory:123).config('cacheable.enabled')).whereRaw('DATE(created_at) = ?', [$date])).with(['dynamicRelation' => fn($q) => $q->where(...)]))..env (e.g., CACHE_DRIVER=redis).redis-cli --latency).php artisan vendor:publish --tag="cacheable-model-config".use ElipZis\Cacheable\Models\Traits\Cacheable.getCacheableProperties() for custom TTL/prefixes.cacheable:Product:where:status,active).create, update, and delete operations.vendor:publish) reduces drift but requires version control for customizations.php artisan cache:clear or tagged cache pruning) for long-running apps.Cache::get('cacheable:Model:query_hash')).withoutCache() to bypass caching for problematic queries.whereNull or orWhere clauses.Model::query()->flushCache()).memory used). Implement size limits or TTL-based eviction.php artisan cache:warmup).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Cache layer down (Redis/Memcached) | All cached queries fall back to DB. | Implement circuit breakers; log cache failures. |
| Cache key collisions | Stale data returned. | Test edge cases; use unique prefixes (e |
How can I help you explore Laravel packages today?