python - How to cache a small piece of information in Django -


i have website delivers list of questions users. set of questions same users. have these questions stored in text file. content of file not change while server running.

i cannot use static page display these questions because have logic decide when show question.

i cache these questions in memory (instead of reading file off hard drive every time user connects). using django 1.7.

i did read caching django's website, think suggested methods (like memcached , database) heavy need. solution situation? use global variable?

thanks!

there many caching back-ends can use listed in https://docs.djangoproject.com/en/1.7/topics/cache/

i haven't tried file system or local memory caching myself, needed memcached, looks they're available, , rest piece of cake!

from django.core import cache  cache_key = 'questions' questions = cache.cache.get(cache_key) # if questions:   # use questions fetched cache else:   questions = { 'question1': 'how you?'} #something serializable has questions   cache.cache.set(cache_key, questions) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -