mikebronner/laravel-model-caching
Speeds up Eloquent by automatically caching model queries and relationships, cutting repetitive database hits. Drop-in package with cache tagging support, configurable cache stores and TTLs, and easy invalidation on model updates—ideal for high-traffic Laravel apps.
Cachable trait integrates directly into the query lifecycle without requiring architectural refactoring.$cachePrefix) aligns with modern SaaS architectures.with()), avoiding over-caching of lazy-loaded or custom queries. This granularity reduces cache bloat and invalidation overhead.cacheCooldownSeconds too long for high-churn models like comments).flushCache() calls in critical paths.MODEL_CACHE_FALLBACK_TO_DB) adds resilience but may mask cache-related bugs during development.$cachePrefix be managed (global vs. per-model)?fallback-to-database be enabled in production, or is cache availability a hard requirement?select() clauses).Post) to validate performance gains and invalidation behavior.disableCache() in critical paths (e.g., admin panels) to ensure no regressions.BaseModel to all Eloquent models, excluding high-churn models (e.g., Comment) until cool-down tuning is complete.MODEL_CACHE_ENABLED=false in staging to verify no cached data leaks into production.cache-prefix and use-database-keying early to avoid refactoring later.spatie/laravel-activitylog). Test with Cache::forget() calls.aws/aws-sdk-php), which may need explicit dependency.Cachable trait to BaseModel or extend CachedModel.laravel-model-caching.php.php artisan modelCache:clear to manually flush all cached models (e.g., during deployments).MODEL_CACHE_STORE) to avoid hardcoding.$cachePrefix, $cacheCooldownSeconds).MODEL_CACHE_FALLBACK_TO_DB=true in development to bypass cache issues.ModelCache::runDisabled() to isolate cache-related bugs.Comment).DB::table() queries bypass invalidation).select() clauses).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Cache backend downtime (Redis/DynamoDB) | Increased DB load; degraded performance. | Enable fallback-to-database; monitor cache health. |
| DynamoDB TTL misconfiguration | Stale cache rows persist indefinitely. | Set TTL on expires_at; test invalidation with modelCache:clear. |
| Partial invalidation (DynamoDB crash) | Transient inconsistencies during invalidation. | Retry invalidations; use cool-down periods for high-churn models. |
Over-caching (e.g., select() queries) |
Cache bloat; reduced hit ratio. | Audit queries; use disableCache() for non-eager-loaded paths. |
| Cool-down period too long | Stale reads during high write load. | Monitor cache age; adjust $cacheCooldownSeconds per model. |
| Multi-tenant prefix conflicts | Cache pollution across tenants. | Validate $cachePrefix uniqueness; use database keying. |
Cachable trait usage, cool-down periods, and DynamoDB invalidation quirks.How can I help you explore Laravel packages today?