PHPackages                             webdeva/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. webdeva/query-cache

ActiveLibrary

webdeva/query-cache
===================

querycachec plugin

v1.0.0(1y ago)00MITPHPPHP &gt;=7.4

Since Dec 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pixelerator/webdeva-query-cache)[ Packagist](https://packagist.org/packages/webdeva/query-cache)[ RSS](/packages/webdeva-query-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Query Cache Package
===================

[](#query-cache-package)

Description
-----------

[](#description)

`webdeva/query-cache` is a Laravel package that provides an easy way to cache Eloquent query results automatically. This package leverages Laravel's cache system to enhance performance by reducing database queries.

---

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

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

Run the following command to include the package in your Laravel project:

```
composer require webdeva/query-cache
```

### Step 2: Add the Trait to Your Models

[](#step-2-add-the-trait-to-your-models)

To enable query caching for a specific model, include the `QueryCacheable` trait in your model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Webdeva\QueryCache\Traits\QueryCacheable;

class Post extends Model
{
    use QueryCacheable;
}
```

---

Usage
-----

[](#usage)

### Caching Queries

[](#caching-queries)

Once the trait is applied to a model, you can cache query results by calling the `cacheQuery` method on the query builder:

```
$posts = Post::query()->cacheQuery();
```

The query result will be cached for **1 hour** (3600 seconds) by default.

### Flushing Cache

[](#flushing-cache)

You can manually clear the cache for a specific query or model by calling the `flushQueryCache` method:

```
Post::flushQueryCache(['some-cache-tags']);
```

---

How It Works
------------

[](#how-it-works)

- The `QueryCacheable` trait adds a global scope to cache query results.
- The cache key is generated using the query SQL and its bindings, ensuring unique caching for every query.
- The default cache duration is set to **3600 seconds (1 hour)**. You can modify this by overriding the `$cacheFor` property in your model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Webdeva\QueryCache\Traits\QueryCacheable;

class Post extends Model
{
    use QueryCacheable;

    // Custom cache duration (e.g., 2 hours)
    public $cacheFor = 7200;
}
```

---

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Laravel &gt;= 10.x

---

Advanced Example
----------------

[](#advanced-example)

### Query with Filters

[](#query-with-filters)

The caching mechanism works seamlessly with filtered queries:

```
$filteredPosts = Post::where('status', 'published')->cacheQuery();
```

### Dynamic Cache Tags

[](#dynamic-cache-tags)

You can assign specific tags for cache management:

```
Post::flushQueryCache(['posts', 'published']);
```

---

Limitations
-----------

[](#limitations)

1. The package currently uses Laravel's default cache store. Ensure that your caching system (e.g., Redis, Memcached) is configured correctly.
2. Be cautious with large datasets, as caching them can increase memory usage.

---

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE).

---

Authors
-------

[](#authors)

Developed and maintained by **Mohammad Khan** ().

---

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

526d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7cfdfb781b486ab6dd8003a4da3cb20df252d05bfd508c9bbc85134bfc13b116?d=identicon)[pixelerator](/maintainers/pixelerator)

---

Top Contributors

[![pixelerator](https://avatars.githubusercontent.com/u/3241842?v=4)](https://github.com/pixelerator "pixelerator (7 commits)")

### Embed Badge

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

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[illuminatech/balance

Provides support for Balance accounting system based on debit and credit principle

16137.4k](/packages/illuminatech-balance)

PHPackages © 2026

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