| Package Data | |
|---|---|
| Maintainer Username: | schickling |
| Maintainer Contact: | schickling.j@gmail.com (Johannes Schickling) |
| Package Create Date: | 2014-01-12 |
| Package Last Update: | 2014-02-05 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-12-10 03:15:58 |
| Package Statistics | |
|---|---|
| Total Downloads: | 696 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 33 |
| Total Watchers: | 4 |
| Total Forks: | 3 |
| Total Open Issues: | 2 |

Simple to use cache layer for your laravel application using memcached & nginx. ~400% faster response times.
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.
Add the following to your composer.json and run composer update
{
"require": {
"schickling/laravel-cash": "dev-master"
}
}
Add Schickling\Cash\CashServiceProvider to your config/app.php
Ajust your nginx vhost (more configurations)
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;
}
}
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();
}));
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');
Cash::rule('POST', 'users', array('users', 'premium/users'));
Cash::rule('POST', 'users/.*/photos', 'photos');
Cash::rule('POST', 'photos', 'photos/*');
Simply restart memcached.