python - Django - queryset caching request-independent? -


i need cache mid-sized queryset (about 500 rows). had on solutions, django-cache-machine being promising.

since queryset pretty static (it's table of cities that's been populated in advance , gets updated me , anyway, never), need serve same queryset @ every request filtering.

in search, 1 detail not clear me: cache sort of singleton object, available every request? mean, if 2 different users access same page, , queryset evaluated first user, second 1 cached queryset?

i not figure out, problem facing. saying classical use case caching. memcache , redis 2 popular options. needs write method or function first tries load result cache, if not there , queries database. e.g:-

from django.core.cache import cache  def cache_user(userid):        key = "user_{0}".format(userid)        value = cache.get(key)        if value none:              # fetch value db              cache.set(value)         return value 

although simplicity, have written function, ideally should manager method of concerned model.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -