New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

mohamadtsn/laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.
2,705

Larablocks Analysis

mohamadtsn/laravel-eloquent-query-cache works with Laravel 10 to 13 (latest release 3.7, Jul 19, 2026).

Laravel 6 to 9 in earlier releases.

Recommendation checks

Solid choice

Solid choice: maintained and up to date, meets 2 of 4 checks; below the bar for Recommended on use.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Jul 19, 2026)
  • 2,097 downloads a month (needs 10,000)
  • 0 GitHub stars (needs 100)

State

Maintained
  • Last stable release: Jul 19, 2026.
  • 1 release in the last 12 months.
  • First released: Nov 21, 2019.
  • Monthly downloads: 2,097.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 3, 2026.

Install
composer require mohamadtsn/laravel-eloquent-query-cache
Latest Version:3.7
Laravel:10 – 13
Older releases:6 – 9
License:Apache-2.0
Last Updated:Jul 19, 2026
Links: GitHub  ·  Packagist
Maintainer: mohamad.borzoyi

Laravel Eloquent Query Cache

Latest Version on Packagist Total Downloads CI License: Apache-2.0

mohamadtsn/laravel-eloquent-query-cache is a maintained fork of the original rennokki/laravel-eloquent-query-cache package.

If you only need the core package behavior, use the original documentation above. This fork keeps the original package experience and adds a few improvements for modern Laravel applications and additional relationship caching scenarios.

Requirements

  • PHP 8.1–8.4
  • Laravel 10.x, 11.x, 12.x, or 13.x

Installation

composer require mohamadtsn/laravel-eloquent-query-cache

This is a library — there is no service provider to register. The trait wires everything by overriding the model's query builder.

Use the trait on models where query caching should be available:

use Mohamadtsn\QueryCache\Traits\QueryCacheable;

class Post extends Model
{
    use QueryCacheable;
}

What This Fork Adds

MorphTo caching support

The original package documentation covers the general caching API. This fork additionally supports cached morphTo relations with inherited cache configuration.

$commentable = $comment->commentable()
    ->cacheFor(now()->addHour())
    ->cacheTags(['commentable'])
    ->cachePrefix('comments')
    ->withPlainKey()
    ->first();

This is useful when you want polymorphic relations to behave the same way as the rest of your cached query chains.

Cache configuration inheritance for relationships

Custom cache options can now flow more consistently into supported relationship queries.

Typical examples:

  • cacheFor(...)
  • cacheTags([...])
  • cachePrefix(...)
  • withPlainKey()
  • cacheDriver(...)

Custom cache repository support

In addition to passing a driver name, you can pass a cache repository instance to cacheDriver():

use Illuminate\Support\Facades\Cache;

$posts = Post::query()
    ->cacheFor(300)
    ->cacheDriver(Cache::store('array'))
    ->get();

This is helpful when integrating the package into more customized application setups or when testing specific cache stores.

Using The Core API

The core query cache API remains aligned with the original package documentation. For the full feature set and the original behavior reference, see:

Common examples:

$posts = Post::cacheFor(3600)->get();

$post = Post::cacheFor(now()->addHour())->first();

$uncached = Post::dontCache()->get();

$tagged = Post::cacheFor(600)->cacheTags(['posts'])->get();

Testing

Tests run on Orchestra Testbench + sqlite. The default cache driver is array.

composer install
composer test                               # full suite (alias for vendor/bin/phpunit)

vendor/bin/phpunit --filter test_name       # single test
vendor/bin/phpunit tests/GetTest.php        # single file

CACHE_DRIVER=redis vendor/bin/phpunit       # exercise a tag-supporting driver

Code style is enforced by StyleCI (Laravel preset). CI runs the suite across PHP 8.1–8.4 × Laravel 10/11/12/13 × prefer-lowest/stable.

If you run the project through Docker:

docker run --rm -u $(id -u):$(id -g) -v "$PWD:/app" -w /app composer:2 sh -lc 'composer install'
docker run --rm -u $(id -u):$(id -g) -v "$PWD:/app" -w /app composer:2 sh -lc 'composer test'

Contributing

Please see CONTRIBUTING for details.

Security

If you discover a security issue, please open a private report with the repository maintainers instead of posting sensitive details publicly.

Alternatives to mohamadtsn/laravel-eloquent-query-cache

watson/rememberable

Query caching for Laravel

6,295,591 1,127
supliu/laravel-query-monitor

Laravel Query Monitor

119,612 283
miradnan/laravel-model-caching

Adding cache for Laravel Eloquent queries

21,977 8
rstriquer/eloquent-logger

Write SQL queries to a file into Laravel "storage/logs" directory.

4,489 4
crysalead/sql-dialect

SQL query builder.

13,603 6

Version History

Version Released PHP Laravel License
3.7 ^10.5|^11.33|^12.0|^13.0 Apache-2.0
3.6.1 ^10.5|^11.33|^12.0 Apache-2.0
3.6.0 ^10.5|^11.33|^12.0 Apache-2.0
3.5.0 ^10.5|^11.33 Apache-2.0
3.4.0 ^9.35|^10.5 Apache-2.0