- How does Lada Cache integrate with Laravel’s Eloquent and Query Builder without manual caching code?
- Lada Cache replaces Laravel’s default query builder with a subclass that automatically intercepts queries. When you add the `LadaCacheTrait` to models or use a `BaseModel`, all queries for those tables are cached transparently. No manual `Cache::remember()` calls are needed—just install, configure, and go.
- Does Lada Cache work with Laravel 13 and PHP 8.3? Are there breaking changes from older versions?
- Yes, Lada Cache 6.x is fully compatible with Laravel 12/13 and PHP 8.3. It’s a focused rewrite addressing past issues, so existing queries and configurations from earlier versions (e.g., 5.x) won’t work without updates. Always check the [upgrade guide](https://github.com/spiritix/lada-cache#version-compatibility) for migration steps.
- Can I exclude specific tables or models from caching?
- Absolutely. Lada Cache allows fine-grained control via the config file (`lada-cache.php`). You can specify `exclude` tables or models to opt out of caching entirely. This is useful for tables with high write volumes or complex queries that don’t benefit from caching.
- How does cache invalidation work for row-level updates or deletes?
- Lada Cache uses Redis tags to track rows and tables. When a model is updated or deleted, it automatically invalidates only the affected rows (via primary key tags) or the entire table if needed. This granular approach minimizes cache stampedes and stale data, unlike traditional table-level invalidation.
- Will Lada Cache work with Redis clusters or failover setups?
- Yes, Lada Cache is designed for Redis clusters and supports failover configurations like Sentinel. However, you must ensure your Laravel Redis connection is properly configured for high availability. Monitor Redis health and consider implementing a circuit breaker for critical paths if outages occur.
- How do I monitor cache performance (hits, misses, invalidations) in production?
- Lada Cache integrates with Laravel Debugbar to visualize cache hits, misses, and invalidations in real time. For production, use the `lada-cache:debug` command or log metrics to Laravel Telescope or Prometheus. This helps identify underperforming queries or invalidation bottlenecks.
- What happens if Redis goes down? Can Lada Cache fall back to direct database queries?
- By default, Lada Cache will throw an exception if Redis is unavailable. To handle failures gracefully, implement a fallback strategy in your `AppServiceProvider` (e.g., catch exceptions and bypass caching for critical queries). The package doesn’t auto-fallback, but you can use `withoutCache()` for specific queries.
- Are there performance tradeoffs for caching complex queries (e.g., joins, subqueries, or raw SQL)?
- Complex queries—especially those with `UNION`, `EXISTS`, or raw SQL—may bypass caching or trigger table-level invalidation instead of row-level. Profile these queries with Debugbar and use `withoutCache()` for unsupported cases. Benchmark to ensure the tradeoff (reduced cache efficiency vs. query correctness) aligns with your needs.
- How do I test Lada Cache in a CI/CD pipeline or staging environment?
- Lada Cache works seamlessly in staging and CI environments if Redis is available. Use the `lada-cache:flush` command to reset the cache between tests. For isolated testing, mock Redis with a local instance (e.g., Docker) or use Laravel’s `Cache::shouldReceive()` in PHPUnit to simulate cache behavior.
- What are the alternatives to Lada Cache, and when should I consider them?
- Alternatives include manual caching with Laravel’s `Cache::remember()`, packages like `spatie/laravel-query-builder-cache`, or database-level caching (e.g., PostgreSQL’s `pg_cache`). Choose Lada Cache if you need **automated, granular, Redis-backed caching** with minimal code changes. Use manual caching for one-off queries or if you’re not using Redis.