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/deleted
composer 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 hours
protected static $fullModelCaching
Boolean
$fullModelCaching
Indicates whether models should be cached directly or converted to an array
Defaults to true
protected static $bustCacheOnSaved
Boolean
$bustCacheOnSaved
Should cache be busted upon saving a model
Defaults to true
protected static $bustCacheOnDeleted
Boolean
$bustCacheOnDeleted
Should cache be busted upon deleting a model
Defaults to true
Model::getLatest($limit, $with, $orderBy);
Integer
$limit
, (*5)
How many records to getAll
Defaults to: 3
String
$orderBy
, (*6)
$orderBy - What column to use when sorting the data
Defaults to: created_at
Array
$with
, (*7)
$with - List of relationships to eager load
Defaults to: An empty array
Returns a Collection or an array, (*8)
Model::getById($id);
Integer
$id
Id of a record you want to get
Returns a Model, an array or null, (*9)
Model::getWhere($column, $value, $with);
String
$column
Column name
Defaults to: id
Mixed
$value
Value to look for
Defaults to: an empty string
Array
$with
An array of relationships to eager load
Defaults to: an empty array
Returns a Collection or an array, (*10)
Model::getAll($with);
Array
$with
An array of relationships to eager load
Defaults to: an empty array
Returns a Collection or an array, (*11)
Model::clearCache();
Model::enableFullModelCaching();
Model::disableFullModelCaching();
MIT, (*12)