I have created an API with Laravel 5 and I want to setup HTTP Caching.
I have the following method:
public function respond($data)
{
$now = new DateTime('now');
$nextHour = new DateTime(date('Y-m-d H:i:s', strtotime('+1 hour', time())));
$options = [
'last_modified' => $now,
'max_age' => config('constants.CACHE_TIME'),
's_maxage' => config('constants.CACHE_TIME'),
'public' => true,
];
$response = response()->json($data, $this->getStatusCode());
$response->setCache($options);
$response->setExpires($nextHour);
return $response;
}
The data as I suppose are cached because when I run an API call with postman to be cached for a time, if I add dd('test') or anything it will not run until the time I have set passes. However, postman shows me the following:
Age → 3
Cache-Control → **no-store, no-cache, must-revalidate**, post-check=0, pre-check=0, public, s-maxage=50
Connection → Keep-Alive
Content-Length → 44198
Content-Type → application/json
Date → Thu, 11 Jun 2015 13:49:04 GMT
Expires → Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive → timeout=5, max=99
**Pragma → no-cache**
Also if I set an Expiration date the header will be sent as 2 dates with the default one and the set expiration date comma separated.
Any help will be appreciated.
Thank you in advance
PS: I use
"barryvdh/laravel-httpcache": "0.2.x@dev"
package