PHPackages                             schickling/laravel-cash - 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. schickling/laravel-cash

ActiveLibrary[Caching](/categories/caching)

schickling/laravel-cash
=======================

Simple to use cache layer for your laravel application using memcached &amp; nginx.

0.3.1(12y ago)336963[2 issues](https://github.com/schickling/laravel-cash/issues)MITPHP

Since Jan 12Pushed 12y ago4 watchersCompare

[ Source](https://github.com/schickling/laravel-cash)[ Packagist](https://packagist.org/packages/schickling/laravel-cash)[ RSS](/packages/schickling-laravel-cash/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (5)Used By (0)

laravel-cash [![Build Status](https://camo.githubusercontent.com/5d933bf69dba248d4717e1dd568bad1b06555302376e9529dff7f19c362daeb2/68747470733a2f2f7472617669732d63692e6f72672f73636869636b6c696e672f6c61726176656c2d636173682e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/schickling/laravel-cash) [![Coverage Status](https://camo.githubusercontent.com/244c6f9dbcc4923f7a50eb45eb852e724503572d84fd17e342098d6da3fe1c59/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f73636869636b6c696e672f6c61726176656c2d636173682f62616467652e706e67)](https://coveralls.io/r/schickling/laravel-cash) [![Total Downloads](https://camo.githubusercontent.com/1657a3c098d8831284dbf0068263e6a3b986412a30036fc1d1c0ca57e2f3f007/68747470733a2f2f706f7365722e707567782e6f72672f73636869636b6c696e672f6c61726176656c2d636173682f646f776e6c6f6164732e706e67)](https://packagist.org/packages/schickling/laravel-cash)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-cash---)

Simple to use cache layer for your laravel application using memcached &amp; nginx. ~400% faster response times.

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

[](#how-it-works)

The packages caches the responses to `GET` requests in memcached using the URL as key. Any further requests get served the cached content by nginx directly without running PHP. Writing actions can easily invalidate the cache.

### Features

[](#features)

- Easy to setup and use
- Self defined invalidation rules
- Automatic cache refilling
- Cache warmup

### Dependencies

[](#dependencies)

- Laravel 4.1
- nginx ([installation guide](https://github.com/schickling/laravel-cash/blob/master/doc/NGINX.md))
- memcached &amp;&amp; PHP memcached extension ([installation guide](https://github.com/schickling/laravel-cash/blob/master/doc/MEMCACHED.md))

Quick setup
-----------

[](#quick-setup)

1. Add the following to your composer.json and run `composer update`

    ```
    {
        "require": {
            "schickling/laravel-cash": "dev-master"
        }
    }
    ```
2. Add `Schickling\Cash\CashServiceProvider` to your config/app.php
3. Ajust your nginx vhost ([more configurations](https://github.com/schickling/laravel-cash/blob/master/doc/NGINX.md))

    ```
    upstream memcached {
        server 127.0.0.1:11211;
        keepalive 1024;
    }

    upstream laravel {
        server 127.0.0.1:9999;
    }

    server {
        listen *:80;
        server_name myapp.dev;

        root /path/to/your/public;
        index index.php;

        rewrite ^/(.*)$ /index.php?/$1 last;

        location ~ \.php$ {
            default_type "application/json";
            if ($request_method = GET) {
                set $memcached_key laravel:$request_uri;
                memcached_pass laravel;
                error_page 404 502 = @nocache;
            }
            if ($request_method != GET) {
                fastcgi_pass laravel;
            }
        }

        location @nocache {
            fastcgi_pass laravel;
        }
    }
    ```

Usage
-----

[](#usage)

### Add cache filter to routes

[](#add-cache-filter-to-routes)

Add the `'after' => 'cash'` filter to `GET` routes you want to be cached. Works also for groups of routes.

```
Route::get('users', array('after' => 'cash', function()
{
	return User::all();
}));
```

### Define invalidation rules

[](#define-invalidation-rules)

Add rules of the following syntax in your `routes.php` file. The `$routeToInvalidate` parameter may be a string or an array and describe always `GET` routes.

```
Cash::rule($httpMethod, $triggerRoute, $routesToInvalidate);
```

Let's say you have a cached `GET users` route to retrieve all users and a `POST users` route to create a new user. Your goal is to invalidate the `GET users` cache if a new user was created.

```
Cash::rule('POST', 'users', 'users');
```

##### Multiple route caches

[](#multiple-route-caches)

```
Cash::rule('POST', 'users', array('users', 'premium/users'));
```

##### Dynamic rules

[](#dynamic-rules)

###### Dynamic trigger routes

[](#dynamic-trigger-routes)

```
Cash::rule('POST', 'users/.*/photos', 'photos');
```

###### Dynamic invalidation routes

[](#dynamic-invalidation-routes)

```
Cash::rule('POST', 'photos', 'photos/*');
```

### Flush cache

[](#flush-cache)

Simply restart memcached.

Coming soon (please contribute a [pull request](https://github.com/schickling/laravel-cash/compare/))
-----------------------------------------------------------------------------------------------------

[](#coming-soon-please-contribute-a-pull-request)

- Support for named routes
- Support for rules in route group scope
- More precise hierarchic invalidation
- Apache support
- Memcache support
- Cache warmup
- Individual cache rewarmup

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.4% 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 ~1 days

Total

4

Last Release

4501d ago

### Community

Maintainers

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

---

Top Contributors

[![schickling](https://avatars.githubusercontent.com/u/1567498?v=4)](https://github.com/schickling "schickling (75 commits)")[![janpio](https://avatars.githubusercontent.com/u/183673?v=4)](https://github.com/janpio "janpio (1 commits)")[![skarolus](https://avatars.githubusercontent.com/u/4314575?v=4)](https://github.com/skarolus "skarolus (1 commits)")

### Embed Badge

![Health badge](/badges/schickling-laravel-cash/health.svg)

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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