Laravel SmartCache is a powerful caching optimization package that dramatically improves your Laravel application's performance through intelligent data compression (up to 70% size reduction), smart chunking, and automatic optimization - all while maintaining the familiar Laravel Cache API you already know and love.
composer require iazaran/smart-cacheThat's it! SmartCache works out-of-the-box with sensible defaults. No configuration required.
Use exactly like Laravel's Cache facade - your existing code works unchanged:
use SmartCache\Facades\SmartCache;
// Basic caching (just like Laravel Cache)
SmartCache::put('users', $users, 3600);
$users = SmartCache::get('users');
// Helper function (just like cache() helper)
smart_cache(['products' => $products], 3600);
$products = smart_cache('products');
// Remember pattern (just like Cache::remember)
$users = SmartCache::remember('users', 3600, function() {
return User::all();
});β¨ The Magic: Your data is automatically compressed and chunked when beneficial, reducing cache size by up to 70%!
// SWR: Serve stale data while refreshing in background
$apiData = SmartCache::swr('github_repos', function() {
return Http::get('https://api.github.com/user/repos')->json();
}, 300, 900); // 5min fresh, 15min stale
// Pattern-based cache clearing
SmartCache::flushPatterns(['user_*', 'api_v2_*']);π― Perfect for Every Use Case:
- π Simple Projects: Drop-in replacement for Laravel's
Cachefacade with automatic optimizations - β‘ Complex Applications: Advanced caching patterns and smart invalidation strategies
- π High-Performance Systems: Real-time monitoring, SWR patterns, and analytics
- π’ Enterprise Solutions: Comprehensive management, HTTP APIs, and production monitoring
- π¦ Intelligent Compression - Up to 70% cache size reduction with automatic gzip compression
- π§© Smart Chunking - Breaks large arrays/objects into manageable pieces for better performance
- π Zero Breaking Changes - Drop-in replacement for Laravel's Cache facade
- β‘ Automatic Optimization - No configuration needed, works out-of-the-box
- π Modern SWR Patterns - Stale-while-revalidate for real-time applications (Laravel 12+)
- π Real-Time Monitoring - Performance metrics and health analysis
- π HTTP Management - Execute cache commands via web interface (no SSH needed)
- π Smart Invalidation - Dependency tracking, pattern-based clearing, model auto-invalidation
Production Results from E-commerce Platform:
- 72% cache size reduction (15MB β 4.2MB)
- 94.3% cache hit ratio
- 23ms average retrieval time
- 800MB daily Redis memory savings
- 40% faster cache retrieval vs standard Laravel Cache
// SWR: Serve stale data while refreshing in background
$data = SmartCache::swr('expensive_api', function() {
return api()->fetchExpensiveData();
}, 300, 900); // 5min fresh, 15min stale
// Pattern-based cache invalidation
SmartCache::flushPatterns(['user_*', 'api_v2_*']);// Performance metrics and health analysis
$metrics = SmartCache::getPerformanceMetrics();
$analysis = SmartCache::analyzePerformance();
// HTTP command execution (no SSH needed)
$status = SmartCache::executeCommand('status', ['force' => true]);composer require iazaran/smart-cacheThat's it! SmartCache works out-of-the-box with sensible defaults. No configuration required for basic usage.
For advanced customization, publish the config:
php artisan vendor:publish --tag=smart-cache-configSupported Laravel Versions: Laravel 8+ through Laravel 12+
For detailed documentation, examples, and advanced usage patterns, visit our comprehensive docs:
// Drop-in replacement for Laravel Cache
SmartCache::put('users', $users, 3600);
$users = SmartCache::get('users');
// Modern SWR patterns (Laravel 12+)
$data = SmartCache::swr('api_data', $callback, 300, 900);
// Pattern-based invalidation
SmartCache::flushPatterns(['user_*', 'api_v2_*']);
// Performance monitoring
$metrics = SmartCache::getPerformanceMetrics();# Quick status overview
php artisan smart-cache:status
# Clear all SmartCache managed keys
php artisan smart-cache:clear
# Clear specific key
php artisan smart-cache:clear expensive_api_call| Driver | Compression | Chunking | SWR Methods | Monitoring |
|---|---|---|---|---|
| Redis | β Full | β Full | β Yes | β Yes |
| File | β Full | β Full | β Yes | β Yes |
| Database | β Full | β Full | β Yes | β Yes |
| Array | β Full | β Full | β Yes | β Yes |
| Memcached | β Yes | β Yes |
SmartCache is 100% compatible with existing Laravel Cache code:
// Your existing Laravel Cache code works unchanged
Cache::put('key', $value, 3600);
$value = Cache::get('key');
// Just change the facade import
// use Illuminate\Support\Facades\Cache; β Old
use SmartCache\Facades\SmartCache; // β
New
// Now you get automatic optimization + new features
SmartCache::put('key', $value, 3600); // Automatically optimized
$value = SmartCache::get('key'); // Automatically restored
// Plus new SWR methods are available immediately
$value = SmartCache::swr('key', $callback); // π Modern patternSmartCache includes 252 comprehensive tests covering all functionality:
composer test
# or with coverage
composer test-coverageWe welcome contributions! See our Contributing Guide for details.
Laravel SmartCache is open-sourced software licensed under the MIT license.
- π Full Documentation: https://iazaran.github.io/smart-cache/
- π¦ Packagist Package: https://packagist.org/packages/iazaran/smart-cache
- π Issue Tracker: https://github.com/iazaran/smart-cache/issues
Built with β€οΈ for the Laravel community
From simple applications to enterprise-scale systems
π·οΈ Keywords: Laravel caching, PHP performance, Redis optimization, SWR patterns, cache monitoring, Laravel 12, enterprise caching, performance analytics, cache invalidation, smart optimization