alex433/laravel-eloquent-cache
Larablocks Analysis
alex433/laravel-eloquent-cache works with Laravel 5 to 13 (latest release v0.9.3, Nov 10, 2026).
Recommendation checks
PromisingPromising: maintained and up to date, meets 2 of 4 checks; not yet widely used.
- Works with Laravel 13, the current version
- Released in the last 12 months (Nov 10, 2026)
- 88 downloads a month (needs 10,000)
- 2 GitHub stars (needs 100)
State
Maintained- Last stable release: Nov 10, 2026.
- 1 release in the last 12 months.
- First released: Feb 24, 2023.
- Monthly downloads: 88, down 66% from six months ago.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Dec 2, 2026.
| Install | |
|---|---|
composer require alex433/laravel-eloquent-cache |
|
| Latest Version: | v0.9.3 |
| PHP: | >=7.1 |
| Laravel: | 5 – 13 |
| License: | MIT |
| Last Updated: | Nov 10, 2026 |
| Links: | GitHub · Packagist |
Laravel Eloquent cache
Laravel's Eloquent models caching
Installation
Install via composer :
composer require alex433/laravel-eloquent-cache
How it works
When Eloquent fetches models by primary key, the SQL query result are cached. Subsequently, when eloquent fetches a model by primary key, the cached result will be used. The cache entry will be flushed when you create, update, or delete a model instance.
Usage
Use the Cachable trait in the models you want to cache.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Alex433\LaravelEloquentCache\Cachable;
class Post extends Model
{
use Cachable;
}
In next cases cache queries will be executed instead SQL queries. Also it do the trick for "belongs To" relations.
Post::find($id); // findOrFail(), findOrNew()
Post::where('id', $id)->first(); // firstOrFail(), firstOrNew(), firstOrCreate(), firstOr()
Post::whereId($id)->first();
Post::where('id', $id)->get();
You can optionally define the following properties to change default trait behavior.
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Alex433\LaravelEloquentCache\Cachable;
class User extends Authenticatable
{
use Notifiable,
Cachable;
/**
* Cache TTL in seconds. Defaults indefinitely
*
* @var int $cacheTtl
*/
public $cacheTtl = 3600;
/**
* Cache store name. Defaults default cache connection
*
* @var string $cacheStore
*/
public $cacheStore = 'redis';
/**
* Cache tags. Defaults no tags
*
* @var array $cacheTags
*/
public $cacheTags = ['users'];
}
To invalidate the cache entry for a model instance, use forget method.
User::find($id)->forget();
// or
User::find($id)->forget()->refresh();
When cache tags is used, you can flush the cache for a model, use the flushCache method.
User::flushCache();
// or
User::find($id)->flushCache();
Related Packages
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v0.9.3 | >=7.1 | ~5.7.0| | MIT | |
| v0.9.2 | >=7.1 | ~5.7.0| | MIT | |
| v0.9.1 | >=7.1 | ~5.7.0| | MIT | |
| v0.9 | >=7.1 | ~5.7.0| | MIT |