From 6694b21362d6e519c68f6497a80404e58858fa3d Mon Sep 17 00:00:00 2001 From: Ismael Azaran Date: Sat, 27 Sep 2025 00:21:58 +0400 Subject: [PATCH 1/4] Enhance README and documentation to include advanced cache invalidation features --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++-- docs/index.html | 40 ++++++++++++++++++++++++++--- 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e113bae..d571524 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ Perfect for **Laravel developers** looking to optimize **cache performance**, re - ๐Ÿ”„ **Laravel-style helper function** support - ๐ŸŽฏ **Redis and file cache driver** optimization - ๐Ÿ“Š **Performance monitoring** and cache statistics +- ๐Ÿ”— **Dependency tracking** - Cascade invalidation with cache hierarchies +- ๐ŸŽฏ **Pattern-based invalidation** - Advanced wildcard and regex pattern matching +- ๐Ÿท๏ธ **Tag-based cache management** - Group and flush related cache entries +- ๐Ÿ”„ **Model-based auto-invalidation** - Automatic cache clearing on Eloquent model changes ## ๐Ÿ“ฆ Installation @@ -86,6 +90,63 @@ public function __construct(\SmartCache\Contracts\SmartCache $cache) } ``` +## ๐Ÿš€ Advanced Cache Invalidation + +SmartCache provides powerful **cache invalidation features** for complex applications: + +### ๐Ÿ”— Dependency Tracking & Cascade Invalidation + +Create cache hierarchies where invalidating a parent automatically clears all dependent children: + +```php +// Create dependencies +SmartCache::dependsOn('user_posts', 'user_data'); +SmartCache::dependsOn('user_stats', 'user_data'); + +// When user_data is invalidated, user_posts and user_stats are automatically cleared +SmartCache::invalidate('user_data'); +``` + +### ๐ŸŽฏ Pattern-Based Invalidation + +Clear multiple cache keys using **wildcards and regex patterns**: + +```php +// Wildcard patterns +SmartCache::flushPattern('user_*'); // Clear all user-related keys +SmartCache::flushPattern('api_response_*'); // Clear all API cache + +// Regex patterns (advanced) +SmartCache::flushPattern('/user_\d+_profile/'); // Clear user profiles with numeric IDs +``` + +### ๐Ÿท๏ธ Model-Based Auto-Invalidation + +Automatically clear cache when **Eloquent models change**: + +```php +use SmartCache\Traits\CacheInvalidation; + +class User extends Model +{ + use CacheInvalidation; + + public function getCacheKeysToInvalidate(): array + { + return [ + "user_{$this->id}_profile", + "user_{$this->id}_stats", + 'users_list_*' + ]; + } +} + +// Cache automatically clears when user is updated/deleted +$user = User::find(123); +$user->name = 'New Name'; +$user->save(); // Related cache keys automatically invalidated! +``` + ## ๐Ÿ”ง Optimization Strategies SmartCache includes several **cache optimization strategies** that intelligently optimize your data: @@ -245,8 +306,10 @@ php artisan smart-cache:clear --force - **Large API response caching** - Optimize storage of external API data - **Database query result caching** - Cache complex query results efficiently +- **Model-based cache invalidation** - Automatic cache clearing for Eloquent models +- **Complex cache hierarchies** - Dependency tracking and cascade invalidation +- **Pattern-based cache management** - Bulk cache operations with wildcards/regex - **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 @@ -289,4 +352,4 @@ Laravel SmartCache is open-sourced software licensed under the [MIT license](LIC 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 +**Keywords**: Laravel caching, PHP cache optimization, Redis optimization, cache compression, Laravel performance, data chunking, cache management, Laravel package, cache invalidation, model observers, dependency tracking diff --git a/docs/index.html b/docs/index.html index 2b085ea..e7f3240 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ - + Laravel SmartCache - Intelligent Caching Optimization