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.

v2.0.0(3w ago)2315MITPHPPHP ^8.2CI passing

Since Jul 27Pushed 3w ago2 watchersCompare

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

READMEChangelog (2)Dependencies (10)Versions (8)Used By (0)

`♥ Made with  And I love `

[![Tests](https://github.com/theriddleofenigma/laravel-rache/actions/workflows/tests.yml/badge.svg)](https://github.com/theriddleofenigma/laravel-rache/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/6f8ae18338825a9bd926f3271c106fd82c720c3c67762c2030e1d3c1a0c18b7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746865726964646c656f66656e69676d612f6c61726176656c2d72616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/theriddleofenigma/laravel-rache)[![Total Downloads](https://camo.githubusercontent.com/7029b494e00c33a41a657cb70a3a285b558b28869a338dfc10df0fae37dc0324/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746865726964646c656f66656e69676d612f6c61726176656c2d72616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/theriddleofenigma/laravel-rache)[![License](https://camo.githubusercontent.com/9baa930abf3af7e23653c99494e64f174f6dadf4cfaee4a9057232062d489799/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746865726964646c656f66656e69676d612f6c61726176656c2d72616368652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

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

[](#laravel-rache)

A super cool package for caching the laravel response dynamically.

Rache caches a route's response and keys it by **rache tags** — small pieces of request state (the authenticated user, the page number, a search term) that you declare. Two requests share a cached response only when every tag agrees they are equivalent, and any tag can be used later as the handle to flush the cache.

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

[](#requirements)

PackagePHPLaravel / Lumen2.x8.2 – 8.412.x, 13.x1.x7.3 – 8.x7.x, 8.x (unmaintained)Laravel 11 is **not** supported. Its final release (11.55.0) carries unpatched security advisories, so Composer's advisory policy refuses to install it.

Rache uses Laravel cache tags, so the cache store must support tagging. The `file`, `database` and `dynamodb` drivers **cannot** be used — pick `redis`, `memcached` or `array`.

Upgrading from 1.x? See [Upgrading from 1.x](#upgrading-from-1x).

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

[](#installation)

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

The service provider, the `Rache` facade alias and the `rache` route middleware alias are registered automatically. The package ships with working defaults, so it is usable immediately — publishing the config is optional.

### Service provider and alias (Lumen only)

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

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

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

Lumen has no middleware alias registry, so register the middleware yourself:

```
$app->routeMiddleware([
    'rache' => \Rache\Middleware\CacheResponse::class,
]);
```

### Config

[](#config)

Publish the config file to `config/rache.php` if you want to change the defaults or register your own tags:

```
php artisan rache:publish
```

### Setting the driver

[](#setting-the-driver)

Point Rache at a taggable cache store in your `.env`:

```
RACHE_DRIVER=redis
```

Leave it unset to use the application's default store. Rache uses the Laravel cache system behind the scenes, so the store must be one configured in `config/cache.php`.

### Middleware

[](#middleware)

The `rache` alias is registered for you. To customise the behaviour, subclass the middleware and register your own alias — Rache will not overwrite it:

```
'rache' => \App\Http\Middleware\CacheResponse::class,
```

Rache tags
----------

[](#rache-tags)

A rache tag turns the current request into the values that make a cached response unique, and doubles as the handle you flush the cache by. `auth`, `page` and `request` are registered by default; you will find them under the `tags` key of `config/rache.php`.

Create your own with either command:

```
php artisan make:rache-tag Search
# or
php artisan rache:make-tag Search
```

Then fill in `getTagDetails()`:

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

…and register it in `config/rache.php`:

```
'tags' => [
    'auth' => \Rache\Tags\Auth::class,       // registered by default
    'page' => \Rache\Tags\Pagination::class, // registered by default
    'request' => \Rache\Tags\Request::class, // registered by default

    'search' => \App\Rache\Tags\Search::class, // yours
],
```

Add as many tags as the route has dimensions that make a response different.

Usage
-----

[](#usage)

Apply the middleware to a **named** route, listing the tags that apply. A `ttl_` parameter overrides the configured lifetime and may appear in any position.

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

```
// Both mean the same thing.
rache:ttl_10,auth,page,search
rache:auth,ttl_10,search,page
```

Notes:

1. TTL values are in **seconds**.
2. The route **must** be named — Rache derives its cache tags from the route name and throws `MissingRouteNameException` otherwise.
3. Tags are optional. `->middleware('rache')` caches the response without varying by anything, which is what you want when a route's response is the same for everyone.
4. Only `GET` and `HEAD` are cached by default. See `cacheable_methods`.

Flushing
--------

[](#flushing)

### Everything

[](#everything)

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

### A tag

[](#a-tag)

```
Rache::flushTag('auth');
```

Clears every cached response carrying the `auth` tag, across all routes.

### A tag on one route

[](#a-tag-on-one-route)

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

Omit `route` and every route carrying the tag is cleared.

### A tag for the current user

[](#a-tag-for-the-current-user)

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

`getTagData()` renders the data exactly as it was rendered when the cache was written.

### A tag for another user

[](#a-tag-for-another-user)

```
$userId = 2;

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

Only user 2's cache is cleared; everyone else's is untouched.

You can flush any tag, with or without a route and data, from anywhere — a model event, an observer, a queued job, an admin action.

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

[](#configuration)

KeyEnvDefaultDescription`enabled``RACHE_ENABLED``true`Master switch. Set to `false` to bypass the cache entirely.`lifetime``RACHE_LIFETIME``3600`Default response lifetime in seconds.`prefix``RACHE_PREFIX``laravel-rache`Prefix applied to every cache key.`cache_store``RACHE_DRIVER`*(app default)*Taggable cache store to use.`cacheable_methods`—`['GET', 'HEAD']`Request methods eligible for caching.`strip_set_cookie_header``RACHE_STRIP_SET_COOKIE_HEADER``true`Remove `Set-Cookie` before storing, so cookies are not replayed to other visitors.`tags`—`auth`, `page`, `request`Registered rache tags.Facade reference
----------------

[](#facade-reference)

MethodDescription`Rache::flushAll(): bool`Flush every response this package cached.`Rache::flushTag(string $tag, array $options = []): bool`Flush a tag, optionally scoped by `route` and/or `data`.`Rache::getTagData(string $tag): array`The tag's data for the current request.`Rache::getTagInstance(string $tag): RacheTagInterface`The tag instance itself.`Rache::getCacheKey(): string`Cache key of the current request.`Rache::getCacheTags(): array`Cache tags of the current request.`Rache::getRouteName(): string`Route name of the current request.`Rache::getLifetime(): int`Lifetime in seconds that applies to the current request.`Rache::racheEnabled(): bool`Whether caching is enabled.`Rache::isInitialized(): bool`Whether the instance has state for the current request.Which responses get cached?
---------------------------

[](#which-responses-get-cached)

A response is cached when **all** of the following hold:

- caching is enabled, and the request method is in `cacheable_methods`
- the status is 2xx or 3xx
- the `Content-Type` is `text/*`, `*/json` or `*+json`, matched case-insensitively
- the response is not a `StreamedResponse` or a `BinaryFileResponse`

Redirects are cached as a flattened plain response, keeping their status and `Location` header.

Upgrading from 1.x
------------------

[](#upgrading-from-1x)

2.0 raises the floor to PHP 8.2 and Laravel 12, and fixes several bugs that changed observable behaviour. See [CHANGELOG.md](CHANGELOG.md) for the full list. The short version:

- Update your PHP and Laravel versions.
- If you disable caching through `RESPONSE_CACHE_ENABLED`, rename it to `RACHE_ENABLED`. The old name still works.
- If `RACHE_DRIVER` was left at the old `file` default, set it to `redis`, `memcached` or `array` — `file` never actually worked.
- Every rache'd route must be named. Unnamed routes now throw instead of silently sharing one cache namespace.
- `POST` and other non-idempotent methods are no longer cached. Add them to `cacheable_methods` if you relied on that.
- Cache keys changed format, so the first deploy runs against a cold cache.

Testing
-------

[](#testing)

```
composer test     # phpunit
composer lint     # pint --test
composer format   # pint
```

The suite runs against a Testbench application and needs no database, cache server or credentials.

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md). Please never paste `.env` contents, cache DSNs, tokens or session cookies into an issue — see [SUPPORT.md](SUPPORT.md).

Security
--------

[](#security)

Report vulnerabilities privately. See [SECURITY.md](SECURITY.md).

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

50

—

FairBetter than 95% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% 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 ~456 days

Total

5

Last Release

22d ago

Major Versions

v1.0.x-dev → v2.0.02026-07-25

PHP version history (2 changes)v1.0.0PHP ^7.3|^8.0

v2.0.0PHP ^8.2

### 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 (12 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

cachelaravellaravel-rachelumenmiddlewareresponse-cacheroutemiddlewarelaravellumencachehttp-cacheresponse-cache

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### 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

[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M315](/packages/laravel-ai)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M227](/packages/laravel-mcp)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[illuminate/queue

The Illuminate Queue package.

20433.0M1.8k](/packages/illuminate-queue)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

265.2k](/packages/aedart-athenaeum)[moonshine/moonshine

Laravel administration panel

1.3k268.2k89](/packages/moonshine-moonshine)

PHPackages © 2026

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