1👍
Contrary to your assertion, Django does not reinitialize on every request. Actually, Django processes last for many requests, and anything defined at module level will be shared across all requests handled by that process. This can often be a cause of thread safety bugs, but in your case is exactly what you want.
Of course a web site normally runs several processes concurrently, and it is impossible to share objects between them. Also, it is up to your server to determine how many processes to spawn and when to recycle them. But one object instantiation per process is better than one per request for your use case.
1👍
0👍
You no need any magic to do singleton-like object in python. Just write module, for example shared.py inside your django project. Put your dictionary initialization here and import it from anywhere.
- [Django]-Django Admin | Group data in object list
- [Django]-Implementing Name Synchronization and Money Transfers in Transactions Model with Account Number Input
- [Django]-What is a main reason that Django webserver is blocking?
- [Django]-Django REST Framework does not intercept 404 exceptions and outputs HTML instead of JSON
- [Django]-Celery+Docker+Django — Getting tasks to work