本文整理匯總了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;
}