Last active
December 22, 2016 15:18
-
-
Save IlianIliev/6efaec46d37ac93262e465e99f41beb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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