Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Smart Cache

Smart Cache Laravel Package

iazaran/smart-cache

Drop-in replacement for Laravel’s Cache facade that automatically compresses and chunks large values, deduplicates unchanged writes, self-heals corrupted entries, and performs cost-aware eviction. Works with existing code (PHP 8.1+, Laravel 8–13).

View on GitHub
Deep Wiki
Context7

Laravel SmartCache - Optimize Caching for Large Data

Frequently asked questions about Smart Cache
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky