本文整理汇总了PHP中Illuminate\Http\Response::setCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setCache方法的具体用法?PHP Response::setCache怎么用?PHP Response::setCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::setCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setCacheHeaders
/**
* Set cache headers and 304 not modify if needed.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
*/
protected function setCacheHeaders($request, $response)
{
if (starts_with($request->getPathInfo(), ['/images'])) {
$stat = stat(session()->pull('requestImagePath'));
} else {
if (($view = $response->getOriginalContent()) instanceof View) {
$stat = stat($view->getPath());
}
}
if (isset($stat)) {
$response->setCache(['etag' => md5("{$stat['ino']}|{$stat['mtime']}|{$stat['size']}"), 'public' => true]);
$response->setExpires(Carbon::now()->addDays(30));
if (null !== ($etag = $request->headers->get('If-None-Match')) || null !== $request->headers->get('If-Modified-Since')) {
$etags = explode('-', $etag, -1);
$request->headers->set('If-None-Match', count($etags) ? $etags[0] . '"' : $etag);
$response->isNotModified($request);
}
}
}
示例2: call
/**
* Call the callback with parameters.
*
* @param callable $callback
* @param array $parameters
* @param int $maxAge
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function call(callable $callback, array $parameters, $maxAge = 0)
{
$response = $this->app->call($callback, $parameters);
if (!$response instanceof SymfonyResponse) {
$response = new Response($response);
}
if ($maxAge) {
$response->setCache(['private' => true, 'max_age' => $maxAge]);
}
return $response;
}