bluesik / laravel-cacheable
Cacheable trait for Laravel models
Installs: 362
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
pkg:composer/bluesik/laravel-cacheable
This package is not auto-updated.
Last update: 2025-12-07 12:57:16 UTC
README
Description
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
Installation
composer require bluesik/laravel-cacheable
Usage
Add at the top of your model file:
<?php use Bluesik\LaravelCacheable\Cacheable;
Then within a class:
use Cacheable;
Available properties
protected $cacheExpiry;
Integer$cacheExpiryA number of minutes till the cache expires.Defaults to 24 hours
protected static $fullModelCaching
Boolean$fullModelCachingIndicates whether models should be cached directly or converted to an arrayDefaults to true
protected static $bustCacheOnSaved
Boolean$bustCacheOnSavedShould cache be busted upon saving a modelDefaults to true
protected static $bustCacheOnDeleted
Boolean$bustCacheOnDeletedShould cache be busted upon deleting a modelDefaults to true
Available methods
Get latest records
Model::getLatest($limit, $with, $orderBy);
-
Integer$limitHow many records to getAllDefaults to: 3
-
String$orderBy$orderBy - What column to use when sorting the dataDefaults to: created_at
-
Array$with$with - List of relationships to eager loadDefaults to: An empty array
Returns a Collection or an array
Get a single record by its id
Model::getById($id);
Integer$idId of a record you want to get
Returns a Model, an array or null
Get records where
Model::getWhere($column, $value, $with);
String$columnColumn nameDefaults to: id
Mixed$valueValue to look forDefaults to: an empty string
Array$withAn array of relationships to eager loadDefaults to: an empty array
Returns a Collection or an array
Get all records
Model::getAll($with);
Array$withAn array of relationships to eager loadDefaults to: an empty array
Returns a Collection or an array
Clear cache for a given model
Model::clearCache();
Enable full model caching
Model::enableFullModelCaching();
Disable full model caching (use arrays instead)
Model::disableFullModelCaching();
License
MIT