Just wondering what would be the best approach for caching external API response. I have used requests-cache before. But not sure if it’s the right way to do it in Django.
Django has a couple different ways to cache information. Can you be more specific - perhaps provide more details about exactly what you’re trying to achieve?
1 Like
the external api is providing data that rarely change. caching the response made sense, but I have no idea what the best practice would be.
Some of the details you need to consider -
- How often does the data change?
- How do you know when your cache is no longer valid?
- Are you notified when the data is changed?
- Does it change on a periodic schedule?
- How much data are you retrieving?
- Are you needing to do any “post-processing” of the data after it’s retrieved?
- Is there a cost associated with retrieving the data?
- How far “out of date” can your data be before it causes a real problem?
- Is this global data being retrieved, or does it vary by user?
All these factors (and possibly others) will influence your design. Cacheing is not a “do everything / one size fits all” issue. You need to understand how that cache is going to interact with the rest of your system.