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 problems #74

Closed
tsubik opened this issue Mar 14, 2017 · 6 comments
Closed

Cache-Control problems #74

tsubik opened this issue Mar 14, 2017 · 6 comments

Comments

@tsubik
Copy link

tsubik commented Mar 14, 2017

Hey @kwhitley I was trying to use this library, but what I see it sets "Cache-Control" to chosen cache duration. I was intending to spare the server heavy database tasks and the cache is controlled by the server, meaning it could be cleared anytime. Setting "Cache-Control" with fixed max-age prevents some clients from hitting my endpoints, even when the cache was cleared by the server. Any workarounds? I believe Cache-Control shouldn't be set in this library or it should be an option.

@tsubik
Copy link
Author

tsubik commented Mar 14, 2017

All right, I can add another middleware after cache middleware to set Cache-Control to other value, but still I think that is a mistake to set Cache-Control to max-age.

@dotob
Copy link

dotob commented May 16, 2017

Hi i want to second tsubik's request to not set this header. or make it optional. or is there a reasonable ides behind it that I do not understand?

From this apart I really like apicache! keep on the good work.

@Balgorn
Copy link

Balgorn commented Jul 24, 2017

@tsubik So basically was dealing with the same problem. What I did right now to get around this issue is to set the duration in the middleware to a very high value (like 1 month). Afterwards I just add a middleware like this:

router.use((req, res, next) => {
	//needed for clients not to get cached content for ages and never retry
	res.header('cache-control', 'no-cache');
	next();
});

@kwhitley
Copy link
Owner

kwhitley commented Aug 9, 2017

@tsubik @dotob @Balgorn This will be resolved in #97. I left the default behavior in to prevent breakage in existing deployed apps, but added the ability to override headers via global (or local middleware) options:

let cache = apicache.options({ headers: { 'cache-control': 'no-cache' } })

That work?

@Balgorn
Copy link

Balgorn commented Aug 9, 2017

That should do it. If you can still set the maximum duration for your local Cache as before.

@kwhitley
Copy link
Owner

@tsubik @Balgorn @dotob - Ability to override headers via headers option (above) has been implemented in v0.9.0 and test coverage included to verify. Feel free to test it out!

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

No branches or pull requests

4 participants