PHPackages                             aqamarine/laravel-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. [Caching](/categories/caching)
4. /
5. aqamarine/laravel-query-cache

ActiveLibrary[Caching](/categories/caching)

aqamarine/laravel-query-cache
=============================

Based on 'miradnan/laravel-model-caching' package which stores cache for database query and automatically cleans it after Creating or Updating Laravel model.

044PHP

Since Apr 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Aqamarine228/LaravelQueryCache)[ Packagist](https://packagist.org/packages/aqamarine/laravel-query-cache)[ RSS](/packages/aqamarine-laravel-query-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-query-cache)

Based on [miradnan/laravel-model-caching](https://github.com/miradnan/laravel-model-caching) package which stores cache for database query and automatically cleans it after Creating or Updating Laravel model.

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

[](#installation)

Using the package manager [composer](https://getcomposer.org).

```
$ composer require aqamarine/laravel-query-cache
```

Usage
-----

[](#usage)

##### for package to work your cache driver has to support 'tags'

[](#for-package-to-work-your-cache-driver-has-to-support-tags)

Add QueryCacheable trait to make model cachable.

```
use Aqamarine228\LaravelQueryCache\QueryCacheable;

class Categories extends Model
{
    use QueryCacheable;

    ...
}
```

In order to cache all model queries you need to set '$cacheFor' model property.

```
public $cacheFor = 3600;
```

Or you can cache only specific queries as in example below.

```
$category = Category::cacheFor(60 * 60)->first();
// or
$category = Category::cacheForever()->first();

// Using a DateTime instance like Carbon works perfectly fine!
$category = Category::cacheFor(now()->addDays(1))->first();
```

### Cache Tags

[](#cache-tags)

This package automatically adds table name tag to every caching query, but you can customise this behavior by setting 'cacheTags' model property.

```
public $cacheTags = ['customTag'];
```

It will replace every caching query default tag with property value.

Alternately you can use tags as it says in [miradnan/laravel-model-caching](https://github.com/miradnan/laravel-model-caching) README

##### if used in builder query, as in example below, cache won't be cleaned automatically

[](#if-used-in-builder-query-as-in-example-below-cache-wont-be-cleaned-automatically)

```
$shelfOneBooks = Book::whereShelf(1)->cacheFor(60)->cacheTags(['shelf:1'])->get();
```

##### so you need to clean it manually

[](#so-you-need-to-clean-it-manually)

```
Book::flushQueryCache(['shelf:1']);
```

### Relationship Caching, Cache Keys, Cache Drivers, Disable caching &amp; Equivalent Methods and Variables

[](#relationship-caching-cache-keys-cache-drivers-disable-caching--equivalent-methods-and-variables)

Topics are the same as in [miradnan/laravel-model-caching](https://github.com/miradnan/laravel-model-caching) README.

### Customisation

[](#customisation)

Because in this package is used only some parts of [miradnan/laravel-model-caching](https://github.com/miradnan/laravel-model-caching)package all customisation possibilities are cut off.

Possible conflicts
------------------

[](#possible-conflicts)

Package QueryCacheable Trait rewrites deleted and saved model events and uses custom CacheBuilder. So every package that does the same thing will conflict. In order to avoid conflict you should use [miradnan/laravel-model-caching](https://github.com/miradnan/laravel-model-caching) package because of it's better flexibility.

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0e9b4376ef918a30937cd636102c5b3ffd13cda37cb3e2630a76af961b9425d?d=identicon)[Aqamarine228](/maintainers/Aqamarine228)

---

Top Contributors

[![Aqamarine228](https://avatars.githubusercontent.com/u/62146368?v=4)](https://github.com/Aqamarine228 "Aqamarine228 (12 commits)")

### Embed Badge

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

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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