This trait allows you to easily cache your model's data through a variety of handful methods.
NOTE:
Cache is automatically cleared when a given model is saved/deleted
composer require bluesik/laravel-cacheable
Add at the top of your model file:
<?php
use Bluesik\LaravelCacheable\Cacheable;
Then within a class:
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
How many records to getAll
Defaults to: 3
-
String
$orderBy
$orderBy - What column to use when sorting the data
Defaults to: created_at
-
Array
$with
$with - List of relationships to eager load
Defaults to: An empty array
Returns a Collection or an array
Model::getById($id);
Integer
$id
Id of a record you want to get
Returns a Model, an array or null
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
Model::getAll($with);
Array
$with
An array of relationships to eager load
Defaults to: an empty array
Returns a Collection or an array
Model::clearCache();
Model::enableFullModelCaching();
Model::disableFullModelCaching();
MIT