- How do I install SmartCache in my Laravel project?
- Run `composer require iazaran/smart-cache`—no additional configuration is required. It seamlessly replaces Laravel’s default Cache facade. Ensure PHP 8.1+ and Laravel 8–13 are installed. Extensions `ext-zlib` and `ext-json` are recommended for full optimization.
- Will SmartCache break my existing caching logic?
- No, SmartCache is a drop-in replacement for Laravel’s Cache facade. All existing methods like `Cache::get()`, `remember()`, or `put()` work unchanged. It extends Laravel’s contracts without overriding them, ensuring backward compatibility.
- Which Laravel versions does SmartCache support?
- SmartCache officially supports Laravel 8 through 13. It aligns with Laravel’s LTS releases and requires PHP 8.1+. If you’re on an older or newer version, check the GitHub repo for compatibility notes or consider alternatives.
- Does SmartCache work with all Laravel cache drivers?
- Yes, SmartCache supports Redis, File, Database, Memcached, and Array drivers out of the box. However, some advanced features like single-flight refresh or circuit breakers rely on the driver’s LockProvider implementation, which may vary in functionality.
- How does SmartCache handle large datasets (e.g., 100K+ items)?
- SmartCache automatically chunks large data to avoid memory issues. For datasets exceeding 100K items, enable `lazy_loading` in the config to fetch data on-demand. Ensure your `memory_limit` is sufficient, as chunking adds overhead. Test with your specific payload sizes.
- Can I disable compression or chunking for specific keys?
- Yes, use the `repository()` method to bypass SmartCache for specific operations. For example, `SmartCache::repository()->put('key', $value)` skips optimizations. Alternatively, configure per-key settings via the `SmartCache::put()` method’s options array.
- What’s the performance impact of SmartCache’s optimizations?
- SmartCache introduces minimal overhead for small payloads (<50 KB), but compression/decompression and chunking add CPU/memory costs. Benchmark your workloads: compression may not justify overhead for tiny data, while chunking helps with large datasets. Monitor hit/miss ratios to validate gains.
- How does SmartCache handle corrupted or stale cache entries?
- SmartCache includes self-healing mechanisms: corrupted entries auto-evict, and stale-while-revalidate (SWR) strategies fetch fresh data in the background. For critical paths, enable `asyncSwr()` (requires Laravel queues) to reduce latency spikes during cache misses.
- Are there alternatives to SmartCache for Laravel caching?
- For basic caching, Laravel’s built-in Cache facade suffices. For advanced optimizations, consider `spatie/laravel-cache-control` (for HTTP caching) or `predis/predis` (Redis-specific optimizations). SmartCache stands out for its automatic compression, chunking, and cost-aware eviction in a single package.
- How do I monitor SmartCache’s performance in production?
- SmartCache provides built-in observability via its dashboard (accessible after publishing the config). Track metrics like hit ratios, eviction rates, and compression savings. Integrate with tools like Laravel Horizon or Prometheus for long-term monitoring. Log warnings for corrupted entries or chunk recovery failures.