sakanjo / laravel-easy-eloquent-memoization
Easy eloquent memoization for Laravel Eloquent models.
Package info
github.com/sakanjo/laravel-easy-eloquent-memoization
pkg:composer/sakanjo/laravel-easy-eloquent-memoization
Fund package maintenance!
v1.0.2
2026-08-09 18:06 UTC
Requires
- php: ^8.2
- illuminate/support: ^10.0 || ^11.0 || ^12.0 || ^13.0
- spatie/laravel-package-tools: ^1.93
Requires (Dev)
- larastan/larastan: ^3.2
- laravel/pint: ^1.1
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.0
This package is auto-updated.
Last update: 2026-08-09 18:08:30 UTC
README
đĨ Easy eloquent memoization
⨠Help support the maintenance of this package by sponsoring me.
Table of Contents
đĻ Install
composer require sakanjo/laravel-easy-eloquent-memoization
đĻ Usage
Setup the model
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use SaKanjo\EasyEloquentMemoization\Concerns\Memoizable; class Post extends Model { use Memoizable; }
Query the model
// Total queries made to the database: 1 Post::query()->get(); // will cache the result Post::query()->get(); // will return the cached result Post::query()->get(); // will return the cached result Post::query()->get(); // will return the cached result Post::query()->get(); // will return the cached result // Total queries made to the database: 1 Post::count(); // will cache the result Post::count(); // will return the cached result Post::count(); // will return the cached result Post::count(); // will return the cached result // Total queries made to the database: 4 Post::query()->withoutMemoization()->get(); // will return the result without caching it Post::query()->withoutMemoization()->get(); // will return the result without caching it Post::query()->withoutMemoization()->get(); // will return the result without caching it Post::query()->withoutMemoization()->get(); // will return the result without caching it
That's it!
đ Functions
withoutMemoization
Post::query()->withoutMemoization()->get();
clearMemoization
$post = Post::query()->first(); $post->clearMemoization(); // will clear the cache for this model Post::query()->first(); // will query the database again and cache the result
clear all memoized queries
use SaKanjo\EasyEloquentMemoization\MemoizeManager; MemoizeManager::clear();
đ Support the development
Do you like this project? Support it by donating
Click the "đ Sponsor" at the top of this repo.
ÂŠī¸ Credits
đ License
MIT License Š 2023-PRESENT Salah Kanjo
