LaravelCachable is a simplified, multi-language model caching trait that works with Redis.
It automatically caches and purges model data on created
, updated
, and deleted
events.
composer require devituz/laravel-cachable
use Cachable;
$product = Product::find(1);
// ๐น Save single record to cache
$product->cacheSingle();
// ๐น Retrieve single record from cache
$cached = Product::getCached(1);
// ๐น Retrieve all records from cache
$all = Product::allCached();
// ๐น Clear cache for a record
$product->forgetCache();