PHPackages                             jakkzing-dev/laravel-cacheable-model - 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. jakkzing-dev/laravel-cacheable-model

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

jakkzing-dev/laravel-cacheable-model
====================================

Automatic query-based model cache for your Laravel app

1.0.0(1y ago)048MITPHPPHP ^8.2|^8.3|^8.4

Since Apr 9Pushed 1y agoCompare

[ Source](https://github.com/Jakkzing-Dev/laravel-cacheable-model)[ Packagist](https://packagist.org/packages/jakkzing-dev/laravel-cacheable-model)[ Docs](https://github.com/elipzis/laravel-cacheable-model)[ GitHub Sponsors](https://github.com/elipZis)[ RSS](/packages/jakkzing-dev-laravel-cacheable-model/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

Automatically cache Laravel Eloquent models by queries
======================================================

[](#automatically-cache-laravel-eloquent-models-by-queries)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4dc0aece738161e13f42728f5aafeb79beddd8d33e512698a96a4404eaee5c39/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c69707a69732f6c61726176656c2d636163686561626c652d6d6f64656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elipzis/laravel-cacheable-model)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2b07a0fbe620cc6e7f2c0cc5bc464548c33c98785dc36fd9916859b0e3399f51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c69707a69732f6c61726176656c2d636163686561626c652d6d6f64656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e)](https://github.com/elipzis/laravel-cacheable-model/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/1bca597dbe06506c44828af363192d57fd8d42c4b64ccfb8e18e223fafee241a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656c69707a69732f6c61726176656c2d636163686561626c652d6d6f64656c2f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e)](https://github.com/elipzis/laravel-cacheable-model/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/fb8ccbe92de7ad6de13add2f2b488f8ff923f8d6d10281296a077a97483bf815/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c69707a69732f6c61726176656c2d636163686561626c652d6d6f64656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elipzis/laravel-cacheable-model)

Easy and automatic select-query caching for your Eloquent models!

- Get cached query results and reduce your database load automatically
- Configure TTL, prefixes, unique-queries etc.
- No manual cache calls needed
- Automated cache flush in case of updates, inserts or deletions

You can make any Eloquent model cacheable by adding the trait

```
...
use ElipZis\Cacheable\Models\Traits\Cacheable;
...

class YourModel extends Model {

    use Cacheable;
    ...
```

and leverage the power of a Redis, memcached or other caches.

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

[](#installation)

You can install the package via composer:

```
composer require elipzis/laravel-cacheable-model
```

You can publish the config file with:

```
php artisan vendor:publish --tag="cacheable-model-config"
```

This is the contents of the published config file:

```
    //Default values for the Cacheable trait - Can be overridden per model
    return [
        //How long should cache last in general?
        'ttl' => 300,
        //By what should cache entries be prefixed?
        'prefix' => 'cacheable',
        //What is the identifying, unique column name?
        'identifier' => 'id',
        //Do you need logging?
        'logging' => [
            'channel' => null, //Which channel should be used?
            'enabled' => false,
            'level' => 'debug',
        ],
    ];
```

Usage
-----

[](#usage)

Make your model cacheable by adding the trait:

```
...
use ElipZis\Cacheable\Models\Traits\Cacheable;
...

class YourModel extends Model {

    use Cacheable;
    ...
```

and then just use your normal model query, for example

```
YourModel::query()->get();
```

```
YourModel::query()->where('field', 'test')->first();
```

```
YourModel::query()->insert([...]);
```

The package overrides the QueryBuilder and scans for the same queries to capture and return the cached values.

You do not need to do anything else but just use your model as you would and leverage the power of cached entries!

### Configuration

[](#configuration)

The following configuration can be overridden per model

```
public function getCacheableProperties(): array {
    return [
        'ttl' => 300,
        'prefix' => 'cacheable',
        'identifier' => 'id',
        'logging' => [
            'channel' => 'anotherChannel',
            'enabled' => false,
            'level' => 'debug',
        ],
    ];
}
```

### Disable cache

[](#disable-cache)

Depending on your cache and database performance, you might like to retrieve a query without caching sometimes:

```
YourModel::query()->withoutCache()->get();
```

### Flush cache

[](#flush-cache)

If your data is updated outside of this package, you can flush it yourself by calling:

```
YourModel::query()->flushCache();
```

### Note on using caching

[](#note-on-using-caching)

This package overrides the native QueryBuilder and is capturing every database query, therefore it imposes a load and performance burden.

If you use caching intensively on a model, this package and its use can help. If an entity is permanently changing, it won't make sense to make it `Cacheable`.

It is recommended to only make models `Cacheable` which have a reasonable caching time in your system. Do not use the trait on any other or all models out of the box, but think about where it makes sense.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [elipZis GmbH](https://elipZis.com)
- [NeA](https://github.com/nea)
- [All Contributors](https://github.com/elipZis/laravel-cacheable-model/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance43

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.7% of commits — single point of failure

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

Unknown

Total

1

Last Release

450d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/192756817?v=4)[Jakkzing-Dev](/maintainers/Jakkzing-Dev)[@Jakkzing-Dev](https://github.com/Jakkzing-Dev)

---

Top Contributors

[![nea](https://avatars.githubusercontent.com/u/392035?v=4)](https://github.com/nea "nea (78 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (33 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (27 commits)")[![Sleepy4k](https://avatars.githubusercontent.com/u/99236402?v=4)](https://github.com/Sleepy4k "Sleepy4k (6 commits)")[![Jakkzing-Dev](https://avatars.githubusercontent.com/u/192756817?v=4)](https://github.com/Jakkzing-Dev "Jakkzing-Dev (2 commits)")[![kingyyy](https://avatars.githubusercontent.com/u/6113718?v=4)](https://github.com/kingyyy "kingyyy (2 commits)")

---

Tags

laravelconfigmodeleloquentcachequeryquerybuilderelipZis

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jakkzing-dev-laravel-cacheable-model/health.svg)

```
[![Health](https://phpackages.com/badges/jakkzing-dev-laravel-cacheable-model/health.svg)](https://phpackages.com/packages/jakkzing-dev-laravel-cacheable-model)
```

###  Alternatives

[elipzis/laravel-cacheable-model

Automatic query-based model cache for your Laravel app

15853.1k](/packages/elipzis-laravel-cacheable-model)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17558.6k](/packages/lacodix-laravel-model-filter)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213420.1k2](/packages/wnx-laravel-backup-restore)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

557.5k](/packages/giacomomasseron-laravel-models-generator)

PHPackages © 2026

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