Yoav Hortman
Yoav Hortman

Reputation: 123

Using a global static variable server wide in Django

I have a very long list of objects that I would like to only load from the db once to memory (Meaning not for each session) this list WILL change it's values and grow over time by user inputs, The reason I need it in memory is because I am doing some complex searches on it and want to give a quick answer back.

My question is how do I load a list on the start of the server and keep it alive through sessions letting them all READ/WRITE to it.

Will it be better to do a heavy SQL search instead of keeping the list alive through my server?

Upvotes: 2

Views: 421

Answers (1)

e4c5
e4c5

Reputation: 53734

The answer is that this is bad idea, you are opening a pandora's box specially since you need write access as well. However all is not lost. You can quite easily use redis for this task.

Redis is a peristent data store but at the same time everything is held in memory. If the redis server runs on the same device as the web server access is almost instantaneous

Upvotes: 1

Related Questions