Skip to content

Instantly share code, notes, and snippets.

@angelmartz
Created December 9, 2013 19:17
Show Gist options
  • Select an option

  • Save angelmartz/7879071 to your computer and use it in GitHub Desktop.

Select an option

Save angelmartz/7879071 to your computer and use it in GitHub Desktop.
cache laravel
Route::filter('cache', function($route, $request, $response = null)
{
$key = 'route-'.Str::slug(Request::url());
if(is_null($response) && Cache::has($key))
{
return Cache::get($key);
}
elseif(!is_null($response) && !Cache::has($key))
{
Cache::put($key, $response->getContent(), 30);
}
});
Route::get('/', array('before' => 'cache', 'after' => 'cache', 'uses' => 'HomeController@show'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment