Cache control (and redirection) for the latest version of a versioned restful resource

╄→гoц情女王★ 提交于 2020-03-05 00:32:30

问题


I am working om ReSTful web service that exposes a versioned resource. I am comfortable with how this works but I have a pedantic question about the 'best' way to handle requests for the latest version of a resource with low latency.

Old versions of the resource are retrievable by version as in

/resource/{version}

Old versions never change. This is a permalink. I can therefore return cache-control: immutable as per https://tools.ietf.org/html/rfc8246 and a max-age of 1 year (as per https://stackoverflow.com/a/25201898/1569204)

The latest version of the resource is retrievable both by its version identifier and via a special URL for "latest" (which just omits specifying a version):

/resource

The resource is not immutable forever (someone could upload a new version) but the particular version we have returned is.

All we can say about the latest version is that no newer version has been uploaded since some time X. So I can set max-age based on X and the current time.

GET /resource
  • Returns the same content as /resource/{version} would for the latest version
  • It includes header link self relation pointing to /resource/{version}
  • Each result also has last-modified and etag headers.

Q Is this "self" relation correct?
(the alternative would be /resource which is what the agent requested and always indicates the latest version)?
I think "cache-control: immutable" is correct in either case?

cache-control: max-age could be based on X for the latest or it could be forever (1 year) for an old version. Which is more correct?


To add mud to the water there is also canonical as a possible alternative to "self".

I expect the most common query to be for the latest version of a resource. So if we were to bother using cache-control: immutable anywhere it would be most valuable here.

A related question is given a request for the latest version of the resource what is the most correct and or efficient way to redirect to the current immutable version?

Using a 303 "see other", seems more correct but would involve two trips for each request rather than return the latest version directly as currently. The approach used here is more like URL rewriting I am aiming for a low-latency service as a matter of principle.

The service works but I would like to make it as pedantically correct and as well designed as possible. As if there were an RFC for ReSTful access to versioned resources. I welcome any constructive criticism.

The only relevant question I've found here is:

https://stackoverflow.com/a/15140665/1569204 where a temporary redirect is recommended.

I've looked at a couple of web-sites for inspiration for example:

  • wikipedia uses: Cache-Control: private, s-maxage=0, max-age=0, must-revalidate for the latest version of page and even old versions which have permalinks and could be immutable

  • stackoverflow seems to use "cache-control: private" for everything

This page shows that immutable is being used in the wild. I haven't found anything discussing its use in web services.

来源:https://stackoverflow.com/questions/60173782/cache-control-and-redirection-for-the-latest-version-of-a-versioned-restful-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!