I am working on a django application. The main task of the application is providing suggestion like "Should I go outside today?". There is only a single endpoint to get the suggestion such as example.com/.
The main logic for providing the suggestion is:
Does the user has any pending task today? (querying from UserTaskModel)
Is today's weather is comfortable? (calculating weather forecasting)
If two user try to fetch data at the same date then the UserTask query will be different. But weather forecast query task will be same. If I use view based django caching then the weather forecast query will be execute for each user. But I want to cache the weather query data for all user at a same date. It can view implement by creating different view for the weather. But I don't want to use another endpoint for the weather.
Django cache set-get method can be use for this task. But is this way is the best way to do this type of task? In my example I use a simple weather calculation query depending the the date. But is this technique is good for complex query?
As you said cache set-get is your solution. but note these two things:
weather_2019_09_22I think creating a utility class can be really good (something like this, this is a pseudo code)
Another idea can be simply creating a model and putting forecasts there, the good point is you will keep the history of forecasts. maybe it can be useful for later queries (and the table won't get too big so you don't need to worry about it)