I'm currently working on this (unfortunately no one responded):
https://stackoverflow.com/questions/31057493/laravel-caching-while-using-ajax
I've changed the code for CacheFilter.php to this:
public function fetch(Route $route, Request $request) {
$key = $this->makeCacheKey($request);
if( Cache::has($key) ) return Cache::get($key);
}
public function put(Route $route, Request $request, Response $response) {
$key = $this->makeCacheKey($request);
if( !Cache::has($key) ) Cache::put($key, $response->getOriginalContent(), 60);
}
protected function makeCacheKey(Request $request) {
$ajaxRequest = json_encode($request->ajax());
if($ajaxRequest == 'true') {
return 'ajax_route_' . Str::slug($request->url());
}
else {
return 'route_' . Str::slug($request->url());
}
}
I'm getting the error:
Serialization of 'Closure' is not allowed
from the following line of code:
if( !Cache::has($key) ) Cache::put($key, $response->getOriginalContent(), 60);
How can I serialize the view response to make this work?