Download the PHP package aminshamim/laravel-model-cache without Composer
On this page you can find all versions of the php package aminshamim/laravel-model-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aminshamim/laravel-model-cache
More information about aminshamim/laravel-model-cache
Files in aminshamim/laravel-model-cache
Package laravel-model-cache
Short Description A Laravel package for automatic model caching with performance optimization
License MIT
Informations about the package laravel-model-cache
Laravel Model Cache
A high-performance Laravel package for automatic model caching with intelligent performance optimization, comprehensive monitoring, and seamless integration.
Features
- 🚀 Automatic Model Caching - Zero-configuration caching with intelligent cache management
- 📊 Performance Monitoring - Built-in cache hit/miss tracking and optimization
- 🎯 Dynamic TTL Adjustment - Automatic cache expiration based on performance metrics
- 🔧 Query Builder Integration - Enhanced Eloquent queries with caching methods
- 🏷️ Cache Tagging - Efficient cache invalidation with tag support
- 📦 Batch Operations - Optimized multi-model caching and retrieval
- 🛡️ Error Resilience - Graceful fallback to database on cache failures
- 🔍 Comprehensive Logging - Detailed debugging and monitoring capabilities
- ⚡ Laravel 11-12 Ready - Full compatibility with latest Laravel versions
Installation
Install via Composer:
Service Provider Registration
The package will automatically register itself via Laravel's package discovery. For manual registration, add to config/app.php:
Publish Configuration
Quick Start
1. Add the Trait to Your Model
2. Start Using Cached Methods
3. Query Builder Integration
Configuration
The package provides extensive configuration options. Here's the default configuration:
bash php artisan vendor:publish --tag=model-cache-config
{prefix}:{model_class}:{primary_key}
model-cache:App\Models\User:123
## Logging
Enable logging in your configuration:
Log messages include:
- Model cached
- Model found in cache
- Model cache forgotten
- Cache errors
## Performance Benefits
1. **Individual Record Access**: Only cache the specific records you need
2. **Reduced Memory Usage**: No need to cache entire query results
3. **Faster Cache Invalidation**: Clear only specific records when they change
4. **Better Cache Hit Rates**: More granular caching leads to better hit rates
5. **Easy Migration**: Option to override `find()` method reduces refactoring effort
## Comparison with Query-Level Caching
| Feature | Query-Level Caching | Model-Level Caching |
|---------|-------------------|-------------------|
| Cache Granularity | Entire query results | Individual records |
| Memory Usage | High (caches all results) | Low (caches only needed records) |
| Cache Invalidation | Clear entire query cache | Clear specific record cache |
| Cache Hit Rate | Lower (specific queries) | Higher (individual records) |
| Performance | Good for repeated queries | Better for individual record access |
## Advanced Usage
### Custom Cache Keys
Override the `getCacheKey` method in your model:
### Conditional Caching
Override the `shouldCache` method:
## Testing
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request
## License
This package is open-sourced software licensed under the [MIT license](LICENSE). All versions of laravel-model-cache with dependencies
laravel/framework Version ^11.0|^12.0
ext-json Version *
ext-redis Version *