PHPackages                             omarseyam/cacheable - 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. omarseyam/cacheable

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

omarseyam/cacheable
===================

A Laravel trait that transparently caches Eloquent query results (including per-user, searchable and paginated results) with a built-in custom paginator and automatic cache invalidation.

v1.0.0(today)02↑2900%MITPHPPHP ^8.1

Since Aug 8Pushed todayCompare

[ Source](https://github.com/OmarSeyam/cacheable)[ Packagist](https://packagist.org/packages/omarseyam/cacheable)[ RSS](/packages/omarseyam-cacheable/feed)WikiDiscussions main Synced today

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

Cacheable
=========

[](#cacheable)

A Laravel trait that transparently caches Eloquent query results — including per-user caching, search filtering, and paginated results — with a built-in custom paginator and automatic cache invalidation.

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

[](#installation)

Install the package via Composer:

```
composer require omarseyam/cacheable
```

No service provider registration is needed — this package only ships a trait and a small helper action class, autoloaded via PSR-4.

Usage
-----

[](#usage)

Add the trait to any Eloquent model:

```
use Illuminate\Database\Eloquent\Model;
use OmarSeyam\Cacheable\Traits\Cacheable;

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

### Basic usage

[](#basic-usage)

```
// Cache all results for one hour (default)
$posts = Post::bring();
```

### Paginated usage

[](#paginated-usage)

```
$posts = Post::bring(
    perPage: 15,
    is_paginate: true,
);
```

### Full signature

[](#full-signature)

```
Post::bring(
    ?callable $callback = null,   // customize the base query, e.g. fn ($query) => $query->where('active', true)
    int $perPage = 10,
    ?string $cache_name = null,   // defaults to the model's table name
    ?int $ttl = null,             // defaults to 1 hour
    string $search_name = 'title',// request() key used for search matching
    ?callable $filter = null,     // extra query filtering callback
    bool $is_paginate = false,
    bool $is_public = false,      // false = cache is scoped per authenticated user
    bool $is_connected = true,    // whether to track this cache key for later invalidation
);
```

### Invalidating the cache

[](#invalidating-the-cache)

```
Post::deletingCache();

// Or invalidate related models' caches too
Post::deletingCache(null, Comment::class);
```

How it works
------------

[](#how-it-works)

- `bring()` builds (or reuses) a query, then serves results from Laravel's cache, keyed by table name (or a custom name you provide), optionally scoped per authenticated user (`Auth::id()`).
- When a search term (via `request($search_name)`) or a `$filter` callback is present, cached results are bypassed and a live, filtered query runs instead.
- When `is_paginate` is `true`, results are paginated with a custom `LengthAwarePaginator` built by `CustomPaginatorAction`, and the count itself is cached separately.
- Every cache key that gets written is tracked (per user) so `deletingCache()` can find and purge all of a model's related cache entries at once.

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

[](#requirements)

- PHP 8.1+
- Laravel 9, 10, 11, 12, or 13

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for more information.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/054d30a8dd18bd23f2840bf66de46334769b09dc0dfa840fb406d93ae15ed777?d=identicon)[OmarSeyam](/maintainers/OmarSeyam)

---

Top Contributors

[![OmarSeyam](https://avatars.githubusercontent.com/u/125864433?v=4)](https://github.com/OmarSeyam "OmarSeyam (1 commits)")

---

Tags

laravelpaginatorpaginationeloquenttraitcachecaching

### Embed Badge

![Health badge](/badges/omarseyam-cacheable/health.svg)

```
[![Health](https://phpackages.com/badges/omarseyam-cacheable/health.svg)](https://phpackages.com/packages/omarseyam-cacheable)
```

###  Alternatives

[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M107](/packages/mongodb-laravel-mongodb)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M156](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k57.2M670](/packages/laravel-scout)[api-platform/laravel

API Platform support for Laravel

58190.1k19](/packages/api-platform-laravel)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k35.7M51](/packages/kirschbaum-development-eloquent-power-joins)

PHPackages © 2026

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