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

ActiveLibrary[Caching](/categories/caching)

suitmedia/laravel-cacheable
===========================

Decorate your repositories and make them cacheable

1.12.0(2y ago)1237.7k↓30%2[1 PRs](https://github.com/suitmedia/laravel-cacheable/pulls)MITPHPPHP ^8.0CI failing

Since Feb 7Pushed 2y ago5 watchersCompare

[ Source](https://github.com/suitmedia/laravel-cacheable)[ Packagist](https://packagist.org/packages/suitmedia/laravel-cacheable)[ Docs](https://github.com/suitmedia/laravel-cacheable)[ RSS](/packages/suitmedia-laravel-cacheable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (20)Used By (0)

[![Build](https://github.com/suitmedia/laravel-cacheable/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/suitmedia/laravel-cacheable/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/5e1c0b0eb4f186c981e2df52bd680938a1b4acd0c87fd94104c3842f41409c5d/68747470733a2f2f636f6465636f762e696f2f67682f737569746d656469612f6c61726176656c2d636163686561626c652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/suitmedia/laravel-cacheable)[![Total Downloads](https://camo.githubusercontent.com/bb118164c5264659711d7ddc6886496e0bf228d38224effe06a4e5f58ade8cd4/68747470733a2f2f706f7365722e707567782e6f72672f737569746d656469612f6c61726176656c2d636163686561626c652f642f746f74616c2e737667)](https://packagist.org/packages/suitmedia/laravel-cacheable)[![Latest Stable Version](https://camo.githubusercontent.com/b0d73206a71140a52ee6b2347c2eb31cfe2383d2fa5b7bdcc822e826b6e20c3f/68747470733a2f2f706f7365722e707567782e6f72672f737569746d656469612f6c61726176656c2d636163686561626c652f762f737461626c652e737667)](https://packagist.org/packages/suitmedia/laravel-cacheable)[![License: MIT](https://camo.githubusercontent.com/f45d904953153ca304a2328243d2733e095eee13a631a1f390709885d41dd692/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2f6672616d65776f726b2f6c6963656e73652e737667)](https://opensource.org/licenses/MIT)

Laravel Cacheable
=================

[](#laravel-cacheable)

> Decorate your repositories and make them cacheable

Synopsis
--------

[](#synopsis)

This package will help you to make your repositories cacheable without worrying about how to manage the cache, and provide an easy way to invalidate the cache. Laravel Cacheable package uses a dynamic decorator class to wrap your existing repository and add the auto-caching feature into it.

Table of contents
-----------------

[](#table-of-contents)

- [Compatibility](#compatibility)
- [Requirements](#requirements)
- [Setup](#setup)
- [Configuration](#configuration)
- [Usage](#usage)
- [License](#license)

Compatibility
-------------

[](#compatibility)

Laravel versionCacheable version5.1.x - 5.4.x1.0.x - 1.3.x5.5.x - 5.8.x1.4.x6.x1.5.x7.x1.6.x8.x1.7.x9.x1.9.x - 1.10.x10.x1.11.x11.x1.12.xRequirements
------------

[](#requirements)

This package require you to use cache storage which supports tags like memcached or redis. You will get errors if you use this package while using any cache storage which does not support tags.

Setup
-----

[](#setup)

Install the package via Composer :

```
$ composer require suitmedia/laravel-cacheable
```

> If you are using Laravel version 5.5+ then you can skip registering the service provider and package alias in your application.

### Register The Service Provider

[](#register-the-service-provider)

Add the package service provider in your `config/app.php`

```
'providers' => [
    // ...
    \Suitmedia\Cacheable\ServiceProvider::class,
];
```

### Register The Package Alias

[](#register-the-package-alias)

Add the package alias in your `config/app.php`

```
'aliases' => [
    // ...
    'Cacheable' => \Suitmedia\Cacheable\Facade::class,
];
```

Configuration
-------------

[](#configuration)

Publish configuration file using `php artisan` command

```
$ php artisan vendor:publish --provider="Suitmedia\Cacheable\ServiceProvider"
```

The command above would copy a new configuration file to `/config/cacheable.php`

```
return [

    /*
    |--------------------------------------------------------------------------
    | Custom Tags
    |--------------------------------------------------------------------------
    |
    | Define all of Eloquent Models which should add custom cache tags
    | automatically to the cached objects.
    |
    */

    'customTags' => \App\User::class,

    /*
    |--------------------------------------------------------------------------
    | Default Cache Duration
    |--------------------------------------------------------------------------
    |
    | Define the default cache duration here.
    | Setting the cache duration to '0' will make the cache lasts forever.
    |
    */

    'duration' => 0,

    /*
    |--------------------------------------------------------------------------
    | Methods which shouldn't be cached
    |--------------------------------------------------------------------------
    |
    | Define a collection of method names which you don't wish
    | to be cached.
    |
    */

    'except' => [
        'cacheDuration',
        'cacheExcept',
        'cacheKey',
        'cacheTags',
        'create',
        'delete',
        'restore',
        'update',
        'updateOrCreate',
    ],
];
```

Usage
-----

[](#usage)

#### Prepare Your Model

[](#prepare-your-model)

Every Model that you wish to be cached should implement the `CacheableModel` contract and use the `CacheableTrait`. The trait will add extra features to your model and observe your model for any future changes. This way, the package will notice whenever the observed model get updated and then it will flush the cache related to the affected model immediately.

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Suitmedia\Cacheable\Contracts\CacheableModel;
use Suitmedia\Cacheable\Traits\Model\CacheableTrait;

class Article extends Model implements CacheableModel
{
    use CacheableTrait;
}
```

#### Prepare Your Repository

[](#prepare-your-repository)

Every Repository that you need to be cached also have to implements the `CacheableRepository` contract. You can implements the contract simply by using the `CacheableTrait` like this :

```
namespace App\Repositories;

use App\Article;
use Suitmedia\Cacheable\Traits\Repository\CacheableTrait;
use Suitmedia\Cacheable\Contracts\CacheableRepository;

class ArticleRepository implements CacheableRepository
{
    use CacheableTrait;

    private $article;

    public function __construct(Article $article)
    {
        $this->article = $article;
    }

    public function model()
    {
        return $this->article;
    }

    /*
    |--------------------------------------------------------------------------
    | Repository's method definition starts from here
    |--------------------------------------------------------------------------
    */

    public function all()
    {
        return $this->model->all();
    }

    public function find($id)
    {
        return $this->model->find($videoId);
    }
}
```

#### Retrieve Data From Repository And Cache The Result

[](#retrieve-data-from-repository-and-cache-the-result)

With this package, you won't need to create new classes to decorate each of your repositories. You can just decorate them using the `Cacheable` facade, and all results of the repository's methods will be cached automatically.

```
// Lets decorate the repository first
$repo = Cacheable::wrap(ArticleRepository::class);

// The result of these codes will be cached automatically
$repo->all();
$repo->find(1);
```

#### Cache Invalidation

[](#cache-invalidation)

This package will help you to invalidate the cache automatically whenever the `CacheableModel` is updated. It will invalidate the cache based on the cache tags which have been defined in your model.

But, you can also invalidate the cache manually using the `Cacheable` facade.

```
// Flush everything
Cacheable::flush();

// Flush the cache using a specific tag
Cacheable::flush('Article');

// Flush the cache using a specific tag,
// and only for the cache which belongs to a specific user
Cacheable::flush('LikedArticle:User:7');
```

License
-------

[](#license)

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

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

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

Every ~123 days

Recently: every ~249 days

Total

19

Last Release

794d ago

PHP version history (8 changes)1.0.0PHP ^5.5.9 || ^7.0

1.1.0PHP ^5.5.9 || ^7.0 || ^7.1.3

1.4.0PHP ^7.1.3

1.5.0PHP ^7.2

1.7.0PHP ^7.3

1.8.0PHP ^7.3||^8.0

1.9.0PHP ^7.4|^8.0

1.12.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5222595?v=4)[Richan Fongdasen](/maintainers/richan-fongdasen)[@richan-fongdasen](https://github.com/richan-fongdasen)

---

Top Contributors

[![richan-fongdasen](https://avatars.githubusercontent.com/u/5222595?v=4)](https://github.com/richan-fongdasen "richan-fongdasen (58 commits)")[![mrofi](https://avatars.githubusercontent.com/u/7432391?v=4)](https://github.com/mrofi "mrofi (5 commits)")

---

Tags

cachelaravellaravel-5-packagerepository-patternlaravelcacherepository pattern

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k10](/packages/dragon-code-laravel-cache)[omaralalwi/lexi-translate

Laravel translation package with morph relationships and caching.

754.3k2](/packages/omaralalwi-lexi-translate)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

1317.7k](/packages/nexxai-laravel-cfcache)[michele-angioni/support

Support is a Laravel package which promotes the use of best practices and design patterns.

181.4k1](/packages/michele-angioni-support)[makbulut/laravel-aerospike

Aerospike cache driver for Laravel

102.2k](/packages/makbulut-laravel-aerospike)

PHPackages © 2026

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