5 ms·
TIL sending a POST request to a URL invalidates the cache for GET requests of the same URL. Going to have to review my REST APIs to make sure that’s not a prob
by zeroimpl 3y ago
TIL sending a POST request to a URL invalidates the cache for GET requests of the same URL.
Going to have to review my REST APIs to make sure that’s not a problem.
- tacone 3y agoIncredible, I did not know that. Does anybody point out to some resources to learn more about this behavior?
- brabel 3y agoI'm sorry, but isn't that the most basic thing possible about GET and POST?? GET is used to read a resource, POST to write to it... why would you NOT expect writing to a resource to invalidate caches of that resource??
- tacone 3y agoBecause usually GET /posts gets you a list of posts, POST /posts create a new one.
- JulianWasTaken 3y agoI don't know what level of incredulity is appropriate in my opinion (probably not as much as the parent comment), but isn't that another good reason to expect cache invalidation? Surely creating new posts would expectedly invalidate the list of posts cached, it has to now include at least one new one.
- zeroimpl 3y agoI think you’d have to have a fairly awkward API design in order for this to be an issue. For example, if “POST /posts” does something else, like flags a post for a moderator to review. That being said, I don’t see this feature being particularly beneficial either. Only the caches which observed the request could know to purge the cache. So you can’t actually rely on it for cache invalidation.