How to proper design a restful API to invalidate a cache?

后端 未结 2 1347
长情又很酷
长情又很酷 2021-02-13 14:53

I have an Application which requires data from Service2, which will return the same answer for a given request, forever, unless its backing database is updated. The database is

2条回答
  •  醉梦人生
    2021-02-13 15:37

    Consider using DELETE instead of POST and for the url:

    /application/cache/ 
    

    In REST, both PUT and DELETEare considered to be indempotent actions. That is, they can be repeated multiple times with the same resulting resource state. In this case, your cache is the resource and multiple DELETE's will result in the same state, a cleared cache.

    You could consider adding a descriptor to your url to clarify that you are clearing the contents of your cache and not deleting the cache object itself. Something like

    /application/cache/contents
    

    perhaps, but that is up to you. Going that route could also potentially let you selectively delete from your cache if necessary.

提交回复
热议问题