Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel sending no-cache header

I'm having trouble with Laravel 4. Somehow the header

Cache-Control: no-cache 

Is always being sent in the response on all pages within my site. I can't find where or how to change it.

Cache-Control: no-cache

Since this is affecting all my controllers where I'm presenting a view with View::Make I would really like a way to change this globally.

like image 707
Kristoffer Svanmark Avatar asked Dec 16 '14 11:12

Kristoffer Svanmark


1 Answers

If you want to use Cache, you can change its behavior in your "Response" object (returned by a controller method in this example) :

public function myControllerMethod() {
    $response = Response::make('something');
    $response->setLastModified(new DateTime("now"));
    $response->setExpires(new DateTime("tomorrow"));
    return $response;
}

It works in my environnement, I hope it will help.

EDIT:

If you want to set it globally, you can try this (in app/start/ directory):

App::after(function($request, $response) {
    $response->setLastModified(new DateTime("now"));
    $response->setExpires(new DateTime("tomorrow"));
});
like image 114
rap-2-h Avatar answered Oct 20 '22 19:10

rap-2-h