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

Best Method to prevent GET caching? #416

Open
JamoCA opened this issue Sep 14, 2021 · 7 comments
Open

Best Method to prevent GET caching? #416

JamoCA opened this issue Sep 14, 2021 · 7 comments

Comments

@JamoCA
Copy link
Contributor

JamoCA commented Sep 14, 2021

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 and Expires headers and return them using the withHeaders() method and, while it works, I thought there might be something else available.

@atuttle
Copy link
Owner

atuttle commented Sep 22, 2021

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();

@JamoCA
Copy link
Contributor Author

JamoCA commented Sep 28, 2021

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();

@atuttle
Copy link
Owner

atuttle commented Oct 4, 2021

That sounds good to me. You volunteering to add it? 😇

@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 11, 2021

Sure. I've written the function and have tested it on my server. Which branch should I add it to?

@atuttle
Copy link
Owner

atuttle commented Oct 12, 2021

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.

@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 12, 2021

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.

@atuttle
Copy link
Owner

atuttle commented Oct 13, 2021

No worries. Looks like you did fine. For reference, you might want to check this out: https://makeapullrequest.com/

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

2 participants