If i have some Django views like 'first', 'second' and so on, and i want to load some data outside this views but use it inside views.
Here is an example to understand my idea.
#function execution time is long, that is why i want to laod it only once when run programm.
fetched_data_from_postgres = some function which load data from postgres and return list with postgres data
def first(request):
#and the i want to use that previous value in all my views
fetched_data_from_postgres = do something
return HttpResponse("first VIEW")
def second(request):
#and the i want to use that previous value in all my views
fetched_data_from_postgres = do something
return HttpResponse("secondVIEW")
def third(request):
#and the i want to use that previous value in all my views
fetched_data_from_postgres = do something
return HttpResponse("third VIEW")
this aproach working well when i run my django project like this python manage.py runserver but when i run with gunicorn or wsgi when i can specify workers count then when worker changes then this variable is lost and need to refresh page to get this previous worker to get that data. It's ridiculous.
Or maybe there is some other aproach to do this job?