Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Smart Cache

Smart Cache stats

Downloads
0
Stars
1
Open Issues
0
Forks
0

View on GitHub →

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

Laravel SmartCache - Intelligent Caching Optimization Package

Laravel SmartCache is a powerful caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

Perfect for Laravel developers looking to optimize cache performance, reduce memory usage, and improve application speed with intelligent data compression and cache management.

๐Ÿš€ Features

  • ๐Ÿ” Auto-detects large cache payloads - Automatically identifies when optimization is needed
  • ๐Ÿ“ฆ Compresses data before caching - Reduces storage requirements with gzip compression
  • ๐Ÿงฉ Chunks large arrays or objects into manageable parts for better performance
  • ๐Ÿง  Intelligent serialization - Advanced data serialization techniques
  • โ™ป๏ธ Seamless retrieval and reconstruction - Transparent data recovery
  • โš™๏ธ Extensible strategy pattern for custom optimizations
  • ๐Ÿ›ก๏ธ Optional fallback for incompatible drivers
  • ๐Ÿ”„ Laravel-style helper function support
  • ๐ŸŽฏ Redis and file cache driver optimization
  • ๐Ÿ“Š Performance monitoring and cache statistics

๐Ÿ“ฆ Installation

Install the package via Composer:

composer require iazaran/smart-cache

Requirements: Laravel 8+ is supported. Tested with Redis and file cache drivers.

โš™๏ธ Configuration

After installation, publish the config file:

php artisan vendor:publish --tag=smart-cache-config

The config file allows you to define thresholds, compression strategies, chunk sizes, and enabled features.

๐Ÿงช Usage

Basic Usage with SmartCache Facade

Use SmartCache just like Laravel's Cache facade:

use SmartCache\Facades\SmartCache;
 
// Store large data with automatic optimization
SmartCache::put('user_data', $largeUserArray, now()->addMinutes(10));
 
// Retrieve data seamlessly
$userData = SmartCache::get('user_data');

Helper Function Usage

Or use the global helper function, similar to Laravel's cache() helper:

// Get a value
$value = smart_cache('cache_key');
 
// Get with default value
$value = smart_cache('cache_key', 'default_value');
 
// Store a value with automatic optimization
smart_cache(['large_dataset' => $bigArray], now()->addMinutes(10));
 
// Access the SmartCache instance
$cache = smart_cache();

Dependency Injection

Or inject it into your services:

public function __construct(\SmartCache\Contracts\SmartCache $cache)
{
$this->cache = $cache;
}

๐Ÿ”ง Optimization Strategies

SmartCache includes several cache optimization strategies out of the box:

  • Compression: Uses gzip or other compression drivers to reduce cache size
  • Chunking: Splits large data structures into manageable chunks
  • Encoding: Serializes data safely for different cache drivers
  • Driver-Aware: Avoids incompatible features based on your cache driver

These strategies can be customized or extended by implementing SmartCache\Contracts\OptimizationStrategy.

๐Ÿ“‚ Example: Large Dataset Caching

// Example: Caching large API response data
$apiData = range(1, 10000); // Large dataset
$complexObject = [
'users' => $userCollection,
'metadata' => $metadataArray,
'statistics' => $statsData
];
 
// SmartCache automatically optimizes storage
SmartCache::put('api_response', $complexObject, 600);
 
// Behind the scenes:
// - Checks data size automatically
// - Compresses or chunks as needed
// - Stores optimization metadata for retrieval
// - Ensures fast reconstruction
 
// Retrieve optimized data
$retrievedData = SmartCache::get('api_response');
 
// Or with helper function
smart_cache(['api_response' => $complexObject], 600);

๐Ÿงฐ Artisan Commands

SmartCache provides helpful Artisan commands for cache management:

# Clear SmartCache data
php artisan smart-cache:clear
 
# Check cache status and statistics
php artisan smart-cache:status

๐ŸŽฏ Use Cases

  • Large API response caching - Optimize storage of external API data
  • Database query result caching - Cache complex query results efficiently
  • Session data optimization - Reduce session storage requirements
  • File-based cache optimization - Improve file cache performance
  • Redis memory optimization - Reduce Redis memory usage
  • High-traffic applications - Improve performance under load

๐Ÿ“Š Performance Benefits

  • Up to 70% reduction in cache storage size
  • Faster cache retrieval for large datasets
  • Reduced memory usage in Redis and other drivers
  • Improved application response times
  • Better resource utilization

๐Ÿ”ง Supported Cache Drivers

  • โœ… Redis - Full feature support with compression and chunking
  • โœ… File Cache - Optimized file-based caching
  • โœ… Database - Database cache driver optimization
  • โœ… Array - In-memory cache optimization
  • โš ๏ธ Memcached - Basic support (limited chunking)

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • Reporting bugs
  • Suggesting features
  • Submitting pull requests
  • Code style guidelines

๐Ÿ“„ License

Laravel SmartCache is open-sourced software licensed under the MIT license.

๐Ÿ”— Links


Built with โค๏ธ for developers who care about Laravel performance optimization and efficient caching strategies.

Keywords: Laravel caching, PHP cache optimization, Redis optimization, cache compression, Laravel performance, data chunking, cache management, Laravel package

iazaran photo

Backend Team Lead

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Iazaran Smart Cache Related Articles

Speeding Up Dashboards - Laravel In Practice EP16 image

Speeding Up Dashboards - Laravel In Practice EP16

Read article
Cache Smart Invalidation - Laravel In Practice EP10 image

Cache Smart Invalidation - Laravel In Practice EP10

Read article
Smart Cache Package for Laravel image

Smart Cache Package for Laravel

Read article
Record and Replay Requests With Laravel ChronoTrace image

Record and Replay Requests With Laravel ChronoTrace

Read article
Top 6 MySQL Database Management Struggles for Laravel Developers (And Smart Fixes) image

Top 6 MySQL Database Management Struggles for Laravel Developers (And Smart Fixes)

Read article
Announcing Inertia 2.0: Redefining Frontend Development for Laravel image

Announcing Inertia 2.0: Redefining Frontend Development for Laravel

Read article
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360ยฐ Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift