Simple trait to easy cache per-method in Laravel.
##How to use it:
Note: This trait can be used in any class.
Features:
- Remember data from cache ( if exists returns or store )
- User Laravel Default TTL time
- Per-method cache level
- Cache become unreachable after a deploy. Auto-purge.
use App\Traits\Cacheable;
class Controller
{
use Cacheable;
}
...
'commit' => env('GIT_COMMIT', null),
...
public function cacheableMethod( $cacheable_parameters )
{
$data = $this->remember(function(){
return 'Cacheable data';
});
return response($data);
}
protected function getTTL()
{
return 10;
}
protected function generateCacheKey($data)
{
return 'key';
}