Open JamoCA opened 2 years ago
Based on the context of your question I'm pretty certain you don't mean server-side caching.
There's no way to guarantee that the client will never cache the response; at least not from the server side. It's just not within our control. However, you seem to have found all of the right headers to suggest to the client that it shouldn't cache the response. There's also ETags to consider, but I think if you've got all of the rest of those you're pretty well covered.
Sounds like maybe we should add a method to easily set them in the response... Something like the following?
return rep(data).neverCache();
Never is a long time. How about noCache()
?
The API response either contains overriding caching directive headers or it doesn't. Setting the cache dates to the past prevents caching so that subsequent GET
requests actually connect to the server without requiring a random cache-busting parameter in the request string.
return rep(data).noCache();
That sounds good to me. You volunteering to add it? 😇
Sure. I've written the function and have tested it on my server. Which branch should I add it to?
I explained the steps here: https://adamtuttle.codes/blog/2014/your-first-github-pull-request/
But tl;dr: fork the repo, create a new branch forked from main, make your change in that branch, push it to your forked repo, and then submit a PR asking to merge your branch into main here.
Ahh... ok. I was looking for a quick recommendation in the repository itself and didn't realize I needed to refer to your blog. (I'm currently using GitHub's web-based GUI to submit changes.) I'll see what I can do as the instructions are a little different for someone who isn't using the console.
No worries. Looks like you did fine. For reference, you might want to check this out: https://makeapullrequest.com/
What's the best way to prevent caching of a GET response to a single URI?
I tried adding
taffy_cache="false"
to the component, but it didn't seem to make any difference.My approach was to generate
Pragma
,Cache-Control
,Last-Modified
andExpires
headers and return them using thewithHeaders()
method and, while it works, I thought there might be something else available.