Skip to content

Instantly share code, notes, and snippets.

@IlianIliev
Last active December 22, 2016 15:18
Show Gist options
  • Save IlianIliev/6efaec46d37ac93262e465e99f41beb2 to your computer and use it in GitHub Desktop.
Save IlianIliev/6efaec46d37ac93262e465e99f41beb2 to your computer and use it in GitHub Desktop.
from django.core.cache import cache
def get_my_choices():
key = 'my-dynamic-choices-key'
res = cache.get(key)
if not res:
# we are casting to list here so we store a list in the cache, not a QuerySet instance)
res = list(User.objects.values_list('id', 'email')) # this is just an example replace it with your model/fields
cache.set(key, res, 60*60*24) # cache for a day
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment