Hello,
I’m trying to use the low-level cache method of Django to keep in memory two dictionnaries i use in my context’s view and that i sometimes need to update, sometimes not.
Here is my settings (but it seems to work well):
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
And here is my view
def Records(request):
#Get cache values or update if not existing (first load or expired)
dic_1 = cache.get_or_set("dic_1", generate_dic_1() , 10*60)
dic_2 = cache.get_or_set("dic_2", generate_dic_2() , 10*60)
#update variablesif buttons clicked
if request.method == 'POST' and "change_dic_1_button" in request.POST:
dic_1 = generate_dic_1()
cache.set("dic_1", dic_1 , 10*60)
elif request.method == 'POST' and "change_dic_2_button" in request.POST:
dic_2 = generate_dic_2()
cache.set("dic_2", dic_1 , 10*60)
return render(request,"Records\myPage.html", {"dic_1" : dic_1; "dic_2" : dic_2})
So in my template i have two buttons, if i click one i want to update dic_1 but updating dic_2 is not necessary, and vis versa.
The problem is that i got an error when i click on a button when the code try to cache.set the corresponding dictionnary. But what i don’t understand is that my error is like
“Can’t pickle <function paginator_number …>: it’s not the same object as django.contrib.admin.templatetags.admin_list.paginator_number”
What i don’t undestand is that i don’t use paginator in this template, and even less in my dictionaries…
I’m sure that the first cache.set before the request check is working well, but the second when it enter the if is raising this error.
Do I use the cache correctly ? Where can it come from ?
Thank you