PHPackages                             theriddleofenigma/laravel-rache - 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. theriddleofenigma/laravel-rache

ActiveLibrary[Caching](/categories/caching)

theriddleofenigma/laravel-rache
===============================

A super cool package for caching the laravel response dynamically.

v1.0.1(4y ago)2314MITPHPPHP ^7.3|^8.0

Since Jul 27Pushed 2y ago2 watchersCompare

[ Source](https://github.com/theriddleofenigma/laravel-rache)[ Packagist](https://packagist.org/packages/theriddleofenigma/laravel-rache)[ Fund](https://www.buymeacoffee.com/riddleofenigma)[ RSS](/packages/theriddleofenigma-laravel-rache/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

`♥ Made with  And I love `

[![Total Downloads](https://camo.githubusercontent.com/7029b494e00c33a41a657cb70a3a285b558b28869a338dfc10df0fae37dc0324/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746865726964646c656f66656e69676d612f6c61726176656c2d72616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/theriddleofenigma/laravel-rache)

Laravel Rache
=============

[](#laravel-rache)

A super cool package for caching the laravel response dynamically.

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

[](#installation)

### Composer Install

[](#composer-install)

You can install the package via composer:

```
composer require theriddleofenigma/laravel-rache
```

### Service provider and Alias \[only for lumen\]

[](#service-provider-and-alias-only-for-lumen)

Add the service provider and alias in the **bootstrap/app.php**.

```
// Service provider
$app->register(\Rache\RacheServiceProvider::class);

// Alias
$app->alias('Rache', \Rache\Facades\Rache::class);
```

#### Note

[](#note)

For laravel, the service provider and aliases will be loaded automatically by the Package Discovery.

### Config

[](#config)

Publish the config file by running the following artisan command. It will publish the rache config file under **config/rache.php**.

```
php artisan rache:publish
```

### Middleware

[](#middleware)

You can either declare the default middleware, or you extend it by creating your own middleware for customisation.

```
'rache' => \Rache\Middleware\CacheResponse::class,
```

### Setting the Driver

[](#setting-the-driver)

Make sure to set the rache driver in the **.env** file with the corresponding driver name which you want to use.

```
RACHE_DRIVER=redis // It uses laravel cache system behind the scenes.
```

#### Note

[](#note-1)

Since rache uses Laravel Cache Tags behind the scenes it contains the same limitations as Laravel Cache tags. Cache tags aren't supported when using the `file`, `dynamodb`, or `database` cache drivers.

### Rache Tags

[](#rache-tags)

Rache tags acts as label for settings up the cache against some data. `Auth`, `Request`, and `Pagination` tags are added by default. You can find them in the rache.php config file under *tags* key.

You can create a Rache tag using the following artisan commands.

```
php artisan make:rache-tag {tag-name}
```

or

```
php artisan rache:make-tag {tag-name}
```

Once you have created the rache tag successfully, then you can configure the dataset in the newly created file under `getTagDetails()` method. The array data returned from the `getTagDetails()` method should contain the key-value pairs of unique dataset, and it will bring the cache dynamic on using with the rache middleware.

Let's add a Rache Tag for search,

Run `php artisan make:rache-tag Search` in the project base directory.

Then add the unique constraints for the search tag under `getTagDetails()`,

```
/**
 * Get the tag details of this rache tag.
 *
 * @return array
 */
public function getTagDetails(): array
{
    return [
        'search' => $this->request->input('search'),
    ];
}
```

After that you should define the newly created tag in the rache.php config file as follows,

```
/*
 * You may declare the tags here. All responses will be tagged.
 * These tags are very used while forgetting the response cache.
 */
'tags' => [
    'auth' => \Rache\Tags\Auth::class, // Added by default
    'page' => \Rache\Tags\Pagination::class, // Added by default
    'request' => \Rache\Tags\Request::class, // Added by default

    // Custom tags
    'search' =>  \App\Rache\Tags\Search::class, // Newly added
],
```

#### Note

[](#note-2)

You can add any number of tags based on the no. of unique constraints they for the route by which the cache will be considered as new.

### In Route

[](#in-route)

Use the middleware along with tags. You can enter the ttl as a tag for settings a different lifetime than the lifetime configured in the rache.php config file. You can pass the ttl in any position along with the other tags.

#### Note

[](#note-3)

1. The lifetime ttl entered are in seconds here.
2. You must have declared the route name in order to rache middleware against a route.
3. You can use the middleware without tags like `->middleware('rache')`. It will cache the response without considering any tag data. It will be useful if a route response won't vary for anyone.

```
// Both acts as same.
rache:ttl_10,auth,page,search
rache:auth,ttl_10,search,page
```

#### Example usage

[](#example-usage)

```
Route::get('/posts', 'PostController@index')
    ->middleware('rache:ttl_10,auth,page,search')
    ->name('posts.index');
```

### Flush all the cached responses

[](#flush-all-the-cached-responses)

By calling the flushAll, you can clear all the cached response in the application.

```
Rache::flushAll();
```

### Flush the tags with route and data

[](#flush-the-tags-with-route-and-data)

You can flush the cache by using `Rache::flushTag({tag-name}, {options:[route, data]})`. We can find some real-time examples for flushing the tags.

#### Case 1

[](#case-1)

Let's say you want to clear all the cache based on the auth tag,

```
Rache::flushTag('auth', [
    'route' => 'posts.index',
]);
```

If the route name is not mentioned, then the cache for all the routes having the auth tag will get cleared.

#### Case 2

[](#case-2)

If you want to clear for the current authenticated user then,

```
Rache::flushTag('auth', [
    'route' => 'posts.index',
    'data' => Rache::getTagData('auth'),
]);
```

The `Rache::getTagData()` will render the data as same as it's get rendered for creating the cache.

#### Case 3

[](#case-3)

In case you want to clear the data for other users,

```
$userId = 2;
Rache::flushTag('auth', [
    'route' => 'posts.index',
    'data' => Rache::getTagInstance('auth')->getTagDetails($userId),
]);
```

If the route name is not mentioned, then the cache for all the routes having the auth tag will get cleared. Here, the auth tag **for userId 2** will get cleared without touching the cache of other userId's.

#### Note

[](#note-4)

You can flush any type of tag along with route name or data based on your need. Ex: On creating new record or delete event or on custom event or an API trigger. You can use it anywhere, whenever a tag has been flushed it will clear all the corresponding cache.

Credits
-------

[](#credits)

- [Kumaravel](https://github.com/theriddleofenigma)
- [All Contributors](../../contributors)

License
-------

[](#license)

Copyright © Kumaravel

Laravel Rache is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~0 days

Total

3

Last Release

1801d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29883026?v=4)[Kumaravel](/maintainers/theriddleofenigma)[@theriddleofenigma](https://github.com/theriddleofenigma)

---

Top Contributors

[![theriddleofenigma](https://avatars.githubusercontent.com/u/29883026?v=4)](https://github.com/theriddleofenigma "theriddleofenigma (6 commits)")

---

Tags

cachelaravellaravel-rachelumenmiddlewareresponse-cacheroute

### Embed Badge

![Health badge](/badges/theriddleofenigma-laravel-rache/health.svg)

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M68](/packages/spatie-laravel-responsecache)[illuminate/cache

The Illuminate Cache package.

12937.0M1.8k](/packages/illuminate-cache)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k89.7k1](/packages/mike-bronner-laravel-model-caching)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21111.6k](/packages/iazaran-smart-cache)

PHPackages © 2026

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