PHPackages                             mohamadtsn/laravel-eloquent-query-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mohamadtsn/laravel-eloquent-query-cache

ActiveLibrary[Database &amp; ORM](/categories/database)

mohamadtsn/laravel-eloquent-query-cache
=======================================

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

3.7(yesterday)01↑2900%Apache-2.0

Since Nov 21Compare

[ Source](https://github.com/mohamadtsn/laravel-eloquent-query-cache)[ Packagist](https://packagist.org/packages/mohamadtsn/laravel-eloquent-query-cache)[ Docs](https://github.com/renoki-co/laravel-eloquent-query-cache)[ GitHub Sponsors](https://github.com/mohamadtsn)[ RSS](/packages/mohamadtsn-laravel-eloquent-query-cache/feed)WikiDiscussions Synced today

READMEChangelog (1)Dependencies (9)Versions (45)Used By (0)

Laravel Eloquent Query Cache
============================

[](#laravel-eloquent-query-cache)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0ab81c961237c08f3d3d09a7d105d08c33a1ad7ff4c67e8c53e6cc852a24838a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f68616d616474736e2f6c61726176656c2d656c6f7175656e742d71756572792d63616368652e7376673f6c6f676f3d7061636b6167697374267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/mohamadtsn/laravel-eloquent-query-cache)[![Total Downloads](https://camo.githubusercontent.com/90e91428f73a510b32607170556bfb36c1988ea348f3e0f989abc4819aa23c0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f68616d616474736e2f6c61726176656c2d656c6f7175656e742d71756572792d63616368652e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://packagist.org/packages/mohamadtsn/laravel-eloquent-query-cache)[![CI](https://camo.githubusercontent.com/26477fd91dcc9d745c542466fc81bcc2534584751ab1973a4e14fda70da38ee6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f68616d616474736e2f6c61726176656c2d656c6f7175656e742d71756572792d63616368652f63692e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d4349)](https://github.com/mohamadtsn/laravel-eloquent-query-cache/actions/workflows/ci.yml)[![License: Apache-2.0](https://camo.githubusercontent.com/bde453f7b5dcc28d625f5e75cb9da9645b204dd3662d2ff4b6b2ceaafafc99ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d79656c6c6f772e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE)

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

- Original repository: [rennokki/laravel-eloquent-query-cache](https://github.com/renoki-co/laravel-eloquent-query-cache)
- Original documentation: [rennokki.gitbook.io/laravel-eloquent-query-cache](https://rennokki.gitbook.io/laravel-eloquent-query-cache/)

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
------------

[](#requirements)

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

Installation
------------

[](#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
-------------------

[](#what-this-fork-adds)

### `MorphTo` caching support

[](#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

[](#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

[](#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
------------------

[](#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:

- [Original package repository](https://github.com/renoki-co/laravel-eloquent-query-cache)
- [Original documentation](https://rennokki.gitbook.io/laravel-eloquent-query-cache/)

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
-------

[](#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
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity70

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~301 days

Total

40

Last Release

1d ago

Major Versions

1.0.x-dev → 2.0.02020-04-27

2.7.0 → 3.0.02021-07-17

2.7.1 → 3.1.32021-11-05

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

1.3.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d4a03e6717c552d241d4af3be9f832ccd62796abb0eca9980f5b642923fa837c?d=identicon)[mohamad.borzoyi](/maintainers/mohamad.borzoyi)

---

Tags

laravelsqleloquentcachingqueryremember

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mohamadtsn-laravel-eloquent-query-cache/health.svg)

```
[![Health](https://phpackages.com/badges/mohamadtsn-laravel-eloquent-query-cache/health.svg)](https://phpackages.com/packages/mohamadtsn-laravel-eloquent-query-cache)
```

###  Alternatives

[rennokki/laravel-eloquent-query-cache

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

1.1k4.4M14](/packages/rennokki-laravel-eloquent-query-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
