- How does this package differ from manually wrapping Eloquent queries with Cache::remember?
- This package replaces Laravel’s query builder entirely with a cache-aware version, so *all* queries (get(), first(), etc.) are cached automatically without manual wrappers. It also handles invalidation via model events, reducing boilerplate significantly.
- Will this break existing query logic (e.g., scopes, relationships, or custom accessors)?
- No—it’s a drop-in replacement. All Eloquent features (scopes, relationships, accessors) work unchanged. The package only intercepts query execution to add caching, leaving your query logic intact.
- What’s the best cache driver for production? Does it support Redis tags?
- Redis is recommended for production due to its atomic operations and tag support. The package leverages Laravel’s built-in cache tagging, so invalidation works efficiently even with bulk operations.
- How does cache invalidation work for bulk updates (e.g., Model::update([...]))?
- Bulk operations bypass individual model events, so you’ll need to manually invalidate tags for affected models. The package provides helper methods like `ModelCache::invalidateTag()` for this purpose.
- Can I mix explicit and transparent caching in the same app?
- Yes. Use `getFromCache()` or `firstFromCache()` for explicit control, while all other queries (e.g., `Model::all()`) remain transparently cached. This lets you fine-tune caching per use case.
- What Laravel versions and PHP versions are officially supported?
- The package supports Laravel 8–12 and PHP 7.4–8.3. It’s tested against the latest LTS releases, ensuring compatibility with modern Laravel stacks and dependencies.
- How do I handle dynamic queries (e.g., whereIn with variable arrays) to avoid cache key collisions?
- The package serializes query parameters into cache keys, but for highly dynamic queries, consider using explicit caching with custom keys or shorter TTLs to mitigate collisions.
- What happens if the cache driver fails (e.g., Redis goes down)?
- The package falls back to the default cache driver (configurable in `config/model-cache.php`). For graceful degradation, implement a circuit breaker to disable caching temporarily during outages.
- How can I monitor cache effectiveness (hit rate, invalidation frequency)?
- Use Laravel’s cache driver metrics (e.g., Redis INFO command) or log cache misses via the `cache_miss` event. The package doesn’t include built-in monitoring, but you can extend it with custom listeners.
- Are there alternatives for caching Eloquent models in Laravel? What makes this package stand out?
- Alternatives like `spatie/laravel-query-builder` or manual `Cache::remember` require manual setup. This package offers transparent caching with zero query changes, automatic invalidation, and deep Eloquent integration—ideal for read-heavy apps.