Best way to cache RESTful API results of GET calls

后端 未结 5 1762
我在风中等你
我在风中等你 2020-12-24 02:34

I\'m thinking about the best way to create a cache layer in front or as first layer for GET requests to my RESTful API (written in Ruby).

Not every request can be ca

5条回答
  •  -上瘾入骨i
    2020-12-24 03:24

    Firstly, build your RESTful API to be RESTful. That means authenticated users can also get cached content as to keep all state in the URL it needs to contain the auth details. Of course the hit rate will be lower here, but it is cacheable.

    With a good deal of logged in users it will be very beneficial to have some sort of model cache behind a full page cache as many models are still shared even if some aren't (in a good OOP structure).

    Then for a full page cache you are best of to keep all the requests off the web server and especially away from the dynamic processing in the next step (in your case Ruby). The fastest way to cache full pages from a normal web server is always a caching proxy in front of the web servers.

    Varnish is in my opinion as good and easy as it gets, but some prefer Squid indeed.

提交回复
热议问题