geoffrich / marvel-by-year

Site to browse Marvel Unlimited by release year.
https://marvel.geoffrich.net/
35 stars 5 forks source link

stale-while-revalidate for Marvel API responses #9

Closed geoffrich closed 2 years ago

geoffrich commented 2 years ago

The Marvel API is slow so we cache the data in Redis for 24 hours. Once the data expires, it's gone from Redis and we have to re-fetch the data.

Instead of deleting the data after 24 hours, it would be nice if we could still return the cached response after 24 hours and update the Redis cache in the background. This data does not change very often so user impact would be minimal. Stale data is much preferred to waiting another 10+ seconds to get the data again.

Not sure if we can do this inside the existing endpoint (i.e. return the cached data but leave an unawaited promise to fetch and update the cache) or if we need to call a separate endpoint to do the update.