DEV Community

Discussion on: REST API and caching?

Collapse
 
brandinchiu profile image
Brandin Chiu • Edited

You typically only cache get requests, and there are services that already exist to do this.

Redis is a very popular one. When a get request is made, you push the result set to redis and store it there for x seconds.

Then every subsequent identical get request would pull the results from redis instead of the database as long as the result set hasn't expired yet.

How you implement this is typically by watching for http caching headers, and determining which of your get requests have low enough turnover that caching is effective.

For example, if your get request relies on having live data, (like getting a count of invoices), then caching might not make sense. You have to decide what level of caching is appropriate for your application.