Where can I place code to read a db table at startup to create an in memory cache?

32 views
Skip to first unread message

B K

unread,
Aug 7, 2018, 8:15:55 AM8/7/18
to Django users

I would like to read a table from the database at startup time to build an in memory cache for fast data retrieval. 

Where is the best place to insert this code to run in django?

thx
bk

Jason

unread,
Aug 7, 2018, 8:53:44 AM8/7/18
to Django users
What other alternatives have you looked at with caching before this?  How long is your cache lifetime, how heavy is your db load, what spikes do you have, what are your bottlenecks.

There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.



B K

unread,
Aug 7, 2018, 11:14:30 AM8/7/18
to Django users
Hello Jason,

This is a project dealing with Internet of Things/5G.

The plan was to cache millions of devices session information in memory for the frequently communicating things and to age out the infrequent things to the database. The in memory search would be done first, If cache hit did not occur, then it would goto the db for the devices that communicate infrequently (once a month, for example a smart meter).

The cache will be up 7x24 all the time, just like DNS.

Project is just starting, meaning that I do not have db load and spikes information as of yet.

I created a micro service using django, REST API, using mariadb and postgres to start. The micro service runs in a docker container and will use K8s or Docker Swarm for orchestration.

What would you recommend for an approach. I am currently just counting on the db (mariadb) to perform caching internally. I was about to run an experiment to compare my approach to just counting on the database.

thx
bk
Reply all
Reply to author
Forward
0 new messages