Wallogit.com
2017 © Pedro Peláez
Cacheable trait for Laravel models
This trait allows you to easily cache your model's data through a variety of handful methods., (*1)
NOTE:, (*2)
Cache is automatically cleared when a given model is saved/deletedcomposer require bluesik/laravel-cacheable
Add at the top of your model file:, (*3)
<?php use Bluesik\LaravelCacheable\Cacheable;
Then within a class:, (*4)
use Cacheable;
protected $cacheExpiry;
Integer $cacheExpiry
A number of minutes till the cache expires.Defaults to 24 hoursprotected static $fullModelCaching
Boolean $fullModelCaching
Indicates whether models should be cached directly or converted to an arrayDefaults to trueprotected static $bustCacheOnSaved
Boolean $bustCacheOnSaved
Should cache be busted upon saving a modelDefaults to trueprotected static $bustCacheOnDeleted
Boolean $bustCacheOnDeleted
Should cache be busted upon deleting a modelDefaults to trueModel::getLatest($limit, $with, $orderBy);
Integer $limit, (*5)
How many records to getAllDefaults to: 3String $orderBy, (*6)
$orderBy - What column to use when sorting the dataDefaults to: created_atArray $with, (*7)
$with - List of relationships to eager loadDefaults to: An empty arrayReturns a Collection or an array, (*8)
Model::getById($id);
Integer $id
Id of a record you want to getReturns a Model, an array or null, (*9)
Model::getWhere($column, $value, $with);
String $column
Column nameDefaults to: idMixed $value
Value to look forDefaults to: an empty stringArray $with
An array of relationships to eager loadDefaults to: an empty array Returns a Collection or an array, (*10)
Model::getAll($with);
Array $with
An array of relationships to eager loadDefaults to: an empty array Returns a Collection or an array, (*11)
Model::clearCache();
Model::enableFullModelCaching();
Model::disableFullModelCaching();
MIT, (*12)