Laravel sends header without cache

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

Cache-Control: no-cache 

Always sent in response to all pages of my site. I can’t find where and how to change it.

Cache-control: no-cache

Since this affects all my controllers where I present the view using View::Make , I really would like to change this globally.

+7
caching laravel laravel-4
source share
2 answers

If you want to use Cache, you can change its behavior in your "Response" object (returned by the 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 environment, I hope it helps.

EDIT:

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

 App::after(function($request, $response) { $response->setLastModified(new DateTime("now")); $response->setExpires(new DateTime("tomorrow")); }); 
+6
source share

To help someone else find the answer for Laravel 5.4, this would be:

 namespace App\Http\Controllers; use DateTime; class MyController extends Controller { public function index() { return response('my content here') ->setLastModified(new DateTime("now")) ->setExpires(new DateTime("tomorrow")); } } 

See also: https://laravel.com/docs/5.4/responses for more information about getting different content (templates, etc.) in the callback.

0
source share

All Articles