Skip to content

Instantly share code, notes, and snippets.

@Ellrion
Last active August 29, 2015 14:03
Show Gist options
  • Save Ellrion/144ac3e7e239a77f40ec to your computer and use it in GitHub Desktop.
Save Ellrion/144ac3e7e239a77f40ec to your computer and use it in GitHub Desktop.
Route simple cache
<?php
//...
Route::filter('http_cache', function($route, $request, $value = 30, $response = null)
{
if ($value instanceof \Illuminate\Http\Response) {
list($response, $value) = [$value, $response];
}
$key = 'route-'.md5(Auth::id().Request::fullUrl().Request::method());
$route->after('http_cache:'.$value);
if ( is_null($response) && Cache::has($key) ) {
return Cache::get($key);
} elseif ( !is_null($response) && !Cache::has($key) ) {
Cache::put($key, $response->getContent(), $value);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment