Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Control Header #12

Open
pchrysa opened this issue Jun 12, 2015 · 5 comments
Open

Cache Control Header #12

pchrysa opened this issue Jun 12, 2015 · 5 comments

Comments

@pchrysa
Copy link

pchrysa commented Jun 12, 2015

I have created an API with Laravel 5 and I want to setup HTTP Caching.

I have the following method:

public function respond($data)
{
    $response = response()->json($data, $this->getStatusCode());
    $response->setTtl(config('constants.CACHE_TIME'));
    return $response;
}

which uses your package

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 in the method in the meantime, 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

How can I make Cache-Control not to return "no-store, no-cache, must-revalidate" and the Pragma not to be "no-cache"?

Any help will be appreciated.

Thank you in advance

PS: Will the package be updated to Laravel 5.1?

@casperbakker
Copy link

You can do that as follows:

$response->header('Cache-Control', 'no-store');
$response->header('Pragma', 'no-cache');

Just before the return.

@barryvdh
Copy link
Owner

Thanks Casper

@pchrysa It should work on L5.1. Do you have any problems?
I recently tagged some releases for this and the dependancies, did that fix it?

@pchrysa
Copy link
Author

pchrysa commented Jun 20, 2015

No the issue still remains. And also if I set an expiration date it will have two dates. The default one and the one that I set eg:

Expires → Thu, 19 Nov 1981 08:52:00 GMT , Sat, 20 Jun 2015 08:52:00 GMT

@casperbakker
Copy link

@pchrysa What webserver do you use? Maybe the webserver is overriding your headers? Setting the headers in my example does really work with default Laravel 5.1 on default Nginx.

@pchrysa
Copy link
Author

pchrysa commented Jun 21, 2015

@Cbakker I have setup an Apache server in Amazon S3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants