Download the PHP package trm42/cache-decorator without Composer
On this page you can find all versions of the php package trm42/cache-decorator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download trm42/cache-decorator
More information about trm42/cache-decorator
Files in trm42/cache-decorator
Package cache-decorator
Short Description Magical (as in saves manual work quite a lot) Cache Decorator for Laravel 5. Designed for usage with repositories but easily usable for other uses. If there's enough interest, can be made framework agnostic.
License GPL-2.0
Informations about the package cache-decorator
(Magical) Cache Decorator for Laravel Repositories
Repositories are really, really nice thing that solves real-world issues and follows the idea of DRY (Don't Repeat Yourself), but making similar classes for repository caching and repeating yourself over and over again for code like this:
And repeat this for every repository class in your project. Lots of dull repetition. Also, it doesn't help to make the caching code as part of your repository base class as it violates the single responsibility principle.
Cue (Magical) Cache Decorator which handles these things automatically for you with just few lines of class declaration:
Aand you're set! The Cache Decorator caches every method call not in the $excludes array.
Please note this the current version doesn't support objects as part of the method call. It will be added to v1.0.0.
If you need something really special handling for some methods you can always override them in the Cached Repository class like this (simple example):
If you happen to use a cache driver that enables you to use cache tags, you can clear the cache automatically when the data changes:
Aaand you're set!
Install
Install with composer:
Copy the default configuration:
Tested with Laravel 5.1 and 5.2.
All versions of cache-decorator with dependencies
illuminate/config Version ~5.0
illuminate/support Version ~5.0
illuminate/log Version ~5.0