-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Invalidate cached URL #853
Comments
Yup, we should offer this. Not sure what the API will look like yet. |
We probably need a mechanism to enumerate the cache. |
Facing exactly the same issue here. I have to force the URL not to be cached at all with Cache-Control: no-store. Is this work in progress? :) |
Actually, it looks like Cache-Control: no-store in the request header is not implemented. Quote from RFC: "If sent in a request, a cache MUST NOT store any part of either this request or any response to it." Source: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.2 |
@andrejvanderzee we fixed that in 2.1. |
Yes thanks confirmed, it is working in 2.1 :) The milestone for invalidating cached URLs changed to 2.2. Will this be in 2014? |
@andrejvanderzee invaliding a specific URL is pretty easy, but what I think most developers will want is a mechanism to invalidate a full URL pattern, like |
At this moment I need a specific URL path. For example, suppose I open a screen with text messages with my user ID with the following URL: @get(/messages/user/{userId}") Then I post a message, leave the screen and come back before Cache-Control expires. In that case, I will be served the cache and my own message is not included. One awkward point is indeed that I have to reconstruct the URL with the user id myself. It would be nice to have an easy way to re-construct the URL from the annotated getMessages(), providing just the userId. It is awkward to keep the syntax of the URL in two places. At this moment I cannot see any use for regular expressions. But I am sure there will be occasions! |
Note that this is not OkHttp's problem. It only knows URLs. |
Yes indeed, its Retrofit. Nevertheless, invalidating exact URLs would be a good solution. |
We are interested by URL pattern invalidation. I think pagination might be a good example where you want invalidate all page URLs at once. |
Hello, is invalidating a specific cached URL possible now? |
@alican yep. Use the iterator to iterate the URLs in the cache, then call |
Thank you Jesse for your answer :) |
@swankjesse or @niqo01 Do either of you have a gist of how to do URL pattern invalidation for cache eviction? Like suggested in the previous comment. |
For a code example, see https://stackoverflow.com/a/68012702/12528345. |
I'd like to be able invalidate an API route / method in the cache.
I have a cached response from /api/route. When I take some action in my app which updates the data on the server, I know that the previous response from /api/route is now invalid, and I need to ensure next time I call that route a network call is made to get the new data.
I'm currently working around this by calling the route with Cache-Control: no-cache set, which seems to work to force a network request and then caches the new response next time it's called without no-cache, but obviously this is not ideal, causing network activity which might never be required (or might then be again invalidated by taking action before /api/route is called again).
I'm using OKHttp as a client in retrofit. See: http://stackoverflow.com/questions/23782531/how-to-invalidate-force-update-of-cache-route-at-next-request-with-retrofit-and
The text was updated successfully, but these errors were encountered: