#Caching (?) user data from external API

1 messages · Page 1 of 1 (latest)

cobalt garnet
#

TLDR: What is the best/secure way to cache authenticated user data? Should I even use cache for it?

I'm using an external API in my Remix application, where each request is authenticated via the api-key header assigned to a user as shown below ⤵️

fetch('https://xyz.com/api/articles', {
  headers: {
    'api-key': api_key
  }
})

The problem is that the response times are long, which negatively affects UX. As I don't think API provider use any caching, is there a way to store this data on the side of my Remix application? I don't need it to be fresh with each request, as it changes only once or twice a day.

Thank you in advance. I appreciate any help.

analog lava
#

Seems like a great opportunity for an in-memory LRU cache, or Redis. You can use the api_key + URL (or a hash of the API key if you want to keep the api keys out of your cache) as the cache key so folks only get the data they specifically requested.

#
#

Dang... I was just re-reading the docs for that package... So handy

cobalt garnet
#

Great, thank you so much!