Laravel 5 - HTTP cache

I have created an API with Laravel 5 and I want to set up 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 is cached as I assume, because when I run an API call with a mail agent that will be cached for a while if I add dd ('test') or anything it won't work until then until I installed the gaps. However, the 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
ConnectionKeep-Alive
Content-Length44198
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
**Pragmano-cache**

      

Also if I set an expiration date the header will be sent as 2 dates with a default value and the expiration date is comma separated.

Any help would be appreciated.

Thank you in advance

PS: I am using

"barryvdh / laravel-httpcache": " 0.2.x@dev "

package

+3


source to share





All Articles