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

ActiveLibrary[Caching](/categories/caching)

kolirt/laravel-cacheable
========================

Easily cache and control class methods without having to remember cache key names

1.1.3(1y ago)150MITPHPPHP &gt;=8.1

Since Aug 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kolirt/laravel-cacheable)[ Packagist](https://packagist.org/packages/kolirt/laravel-cacheable)[ Docs](https://github.com/kolirt/laravel-cacheable)[ Fund](https://www.buymeacoffee.com/kolirt)[ RSS](/packages/kolirt-laravel-cacheable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

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

[](#laravel-cacheable)

Easily cache and control class methods without having to remember cache key names

Structure
---------

[](#structure)

- [Getting started](#getting-started)
    - [Requirements](#requirements)
    - [Installation](#installation)
    - [Setup](#setup)
- [Console commands](#console-commands)
- [Methods](#methods)
    - [cache](#cache)
    - [clearCache](#clearcache)
    - [updateCache](#updatecache)
    - [refreshCache](#refreshcache)
    - [setCacheTime](#setcachetime)
    - [flushAllCache](#flushallcache)
    - [appendCacheTags](#appendcachetags)
- [FAQ](#faq)
- [License](#license)
- [Other packages](#other-packages)

[ ![Buy Me A Coffee](https://camo.githubusercontent.com/a6ebf9f3a5d0689c6d7449b0ea0c4ce75bbff5ef09b38babf991cb7a559f8774/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f617269616c2d79656c6c6f772e706e67)](https://www.buymeacoffee.com/kolirt)Getting started
---------------

[](#getting-started)

Easily cache and control class methods without having to remember cache key names

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10

### Installation

[](#installation)

```
composer require kolirt/laravel-cacheable
```

### Setup

[](#setup)

Publish config file

```
php artisan cacheable:install
```

By default, Laravel has a problem with multitags, which leads to excessive duplication of data in the cache and unexpected behavior when clearing and reading the cache. You can read more about it [here](https://github.com/laravel/framework/issues/25234). To fix this issue, add the following code to the `composer.json` and run `composer dump-autoload`

```
{
    "autoload": {
        "exclude-from-classmap": [
            "vendor/laravel/framework/src/Illuminate/Cache/TaggedCache.php"
        ],
        "files": [
            "vendor/kolirt/laravel-cacheable/src/Overrides/TaggedCache.php"
        ]
    }
}
```

Use the `Cacheable` trait in the target class

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;
}
```

Console commands
----------------

[](#console-commands)

- `cacheable:install` - Install cacheable package
- `cacheable:publish-config` - Publish the config file

Methods
-------

[](#methods)

#### `cache`

[](#cache)

Using the `cache` method, cache everything you need

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    public function exampleMethod()
    {
        return $this->cache(fn () => 'example data');
    }

    public function exampleMethodWithParams(int $id)
    {
        return $this->cache(fn () => 'example data with id ' . $id);
    }
}
```

#### `clearCache`

[](#clearcache)

To clear the cache, use the `clearCache` method

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    public function clearExampleMethod()
    {
        $this->clearCache('exampleMethod');
    }

    public function clearExampleMethodWithParams(int $id)
    {
        $this->clearCache('exampleMethodWithParams', $id);
    }
}
```

#### `updateCache`

[](#updatecache)

To update the cache, use the `updateCache` method

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    public function updateExampleMethod()
    {
        $this->updateCache('exampleMethod', 'new example data');
    }
}
```

#### `refreshCache`

[](#refreshcache)

To refresh the cache, use the `refreshCache` method

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    public function exampleMethod() {
        return $this->cache(fn () => 'example data');
    }

    public function refreshExampleMethod()
    {
        $this->refreshCache('exampleMethod');
    }
}
```

#### `setCacheTime`

[](#setcachetime)

To set the cache time, use the `setCacheTime` method

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    public function __construct()
    {
        $this->setCacheTime(now()->endOfDay());
    }
}
```

#### `flushAllCache`

[](#flushallcache)

Clearing the all cache works on tags. You have to switch the class to taggable mode

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    protected bool $taggable = true;
}
```

Or you can add tags to the class by using the `appendCacheTags` method without taggable mode

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    public function __construct() {
        $this->appendCacheTags(['tag1', 'tag2']);
    }
}
```

To flush all cache, use the `flushAllCache` method

```
$example = new Example();
$example->flushAllCache();
```

#### `appendCacheTags`

[](#appendcachetags)

In addition to the basic tag that is added automatically in taggable mode, you can add additional tags that you need using the `appendCacheTags` method

```
use Kolirt\Cacheable\Traits\Cacheable;

class Example
{
    use Cacheable;

    protected bool $taggable = true;

    /** add additional tags for all methods */
    public function __construct()
    {
        $this->appendCacheTags(['tag1', 'tag2']);
    }

    /** or add additional tags for specific method */
    public function exampleMethod()
    {
        $this->appendCacheTags(['tag1', 'tag2']);
        return $this->cache(fn () => 'example data');
    }
}
```

Then, through Cache facade, you can delete the cache for the tag you need

```
use Illuminate\Support\Facades\Cache;

Cache::tags(['tag1'])->flush();
Cache::tags(['tag2'])->flush();
Cache::tags(['tag1', 'tag2'])->flush();
```

FAQ
---

[](#faq)

Check closed [issues](https://github.com/kolirt/laravel-cacheable/issues) to get answers for most asked questions

License
-------

[](#license)

[MIT](LICENSE.txt)

Other packages
--------------

[](#other-packages)

Check out my other packages on my [GitHub profile](https://github.com/kolirt)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance49

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Every ~41 days

Recently: every ~55 days

Total

7

Last Release

379d ago

### Community

Maintainers

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

---

Top Contributors

[![kolirt](https://avatars.githubusercontent.com/u/11573343?v=4)](https://github.com/kolirt "kolirt (13 commits)")

---

Tags

laravellaravel-cachelaravel-packagelaravelcachecacheablelaravel-cachecacheable-methodscacheable-method

### Embed Badge

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

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

###  Alternatives

[imanghafoori/laravel-widgetize

A minimal yet powerful package to give a better structure and caching opportunity for your Laravel apps.

909137.9k12](/packages/imanghafoori-laravel-widgetize)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[arifhp86/laravel-clear-expired-cache-file

Remove laravel expired cache file/folder

36128.7k](/packages/arifhp86-laravel-clear-expired-cache-file)[karriere/state

Laravel package for storing current application state in cache/session

1718.5k](/packages/karriere-state)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)[salehhashemi/laravel-configurable-cache

Configurable Laravel cache manager

2114.5k1](/packages/salehhashemi-laravel-configurable-cache)

PHPackages © 2026

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