I have been given a project recently where REST API have been implemented in the most basic way possible i.e. request comes to app, app hits controller, queries db, returns response.
So this mechanism, as its quite obvious, has started to create issues in terms of response times as data has grown a lot. Plus this approach also hogs the infrastructure a lot as well through its processing.
Now, I'm familiar with caching mechanisms for APIs and non API things, but what are the recommended ways to do it in case of APIs? Also, what do we need to add in terms of infrastructure and code modules to handle such sort of a thing?
Some test cases for different approaches would be really nice by any of the well-versed folks.
Best Answer
For a REST service, you usually want to use the available caching mechanisms of the web and the HTTP protocol. That means using caching directives or entity tags in the responses.
In this context, what you want to do is to completely eliminate some requests to certain resources or limit the work that the server needs to do once a request is received.
You need to analyze your application and:
You should do a search online for something like "REST API caching strategies" and see if something else might be more suitable for your case.
Now, of course, caching doesn't happen on it's own. You need to implement it. That means: