Caching daily data in Django, and caching more on request
I'm currently building a website where I each day want yesterday's financial data cached for the full day, to be quickly available to users. I also want to cache older data on request, e.g. if a user looks at data for some date in 2023, I also want to cache that, although for a shorter time (say maybe 1 h).
Being new to Django, I've tried to read up on the different caching solutions that Django offers, but I'm a bit confused as to which would server me well.
- Does Django offer a solution fit for this purpose?
- Would it be easier to set up a manual caching process, which fetches cached data if it exists, and otherwise retrieves and caches it for a specfied time period?
- If so, what would such a solution look like?
Thank you.
Edit: Would it be a bad idea to do this with middleware, by assigning the data as an instance (or class) variable? The caching options (e.g. memcache) seem to be quite restrictive on file size; since the financial data can be quite large (~50 MB), this doesn't seem like an optimal solution. However, I'm not quite sure about how long a class-based middleware instance "lives"?