Download the PHP package bennett-treptow/laravel-cached-mutators without Composer
On this page you can find all versions of the php package bennett-treptow/laravel-cached-mutators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bennett-treptow/laravel-cached-mutators
More information about bennett-treptow/laravel-cached-mutators
Files in bennett-treptow/laravel-cached-mutators
Package laravel-cached-mutators
Short Description Cached model mutators
License MIT
Homepage https://github.com/bennett-treptow/laravel-cached-mutators
Informations about the package laravel-cached-mutators
Laravel Cached Mutators
This package provides a trait for your Eloquent models to automatically cache any mutators and attributes you choose. Good use cases for this trait are for expensive mutators that you only want to run once per request / certain time period and want to keep your mutator code free from any manual caching.
This package works by hooking into the Eloquent model's getAttributeValue
function, and passing thru the value if the specified attribute does not need to be cached as per the $cacheAttributes
.
Install
composer require bennett-treptow/laravel-cached-mutators
Usage
Basic Usage
Advanced Usage
The $cacheAttributes
array can be configured to cache mutators per attribute by defining store
and ttl
.
By default, the store
will follow your application's default cache store, which is usually the file
store.
Defining a ttl
will call the cache repository's remember
function, and making ttl
null or not part of the array will use the cache repository's rememberForever
function.
You may also override the defaultCacheStore()
and defaultCacheTTL()
functions on your models to expedite the process of choosing where each attribute is cached.
Clearing Cached Mutators
Need to clear your cached mutators to get a fresh copy?