如何序列化视图响应?

时间:2015-06-29 15:28:19

标签: php laravel caching

我正在研究这个问题(遗憾的是没有人回复):

https://stackoverflow.com/questions/31057493/laravel-caching-while-using-ajax

我已将CacheFilter.php的代码更改为:

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());
    }
}

我收到了错误:

Serialization of 'Closure' is not allowed

来自以下代码行:

if( !Cache::has($key) ) Cache::put($key, $response->getOriginalContent(), 60);

如何序列化视图响应以使其工作?

0 个答案:

没有答案