python - Redis auto update cache -


i using django-redis cache , saving data in redis cache when update database don't find updated data in redis cache.

my code :

from django.shortcuts import render myapp.models import students rest_framework.views import apiview rest_framework.response import response django.core.cache import cache   class userlistview(apiview):      def get(self, request):          data = cache.get('alldata')          if not data:              data = students.objects.values('cache_id', 'username',  'email')             cache.set('alldata', data) 

in settings.py have following items in middleware class:

middleware_classes = ( 'django.middleware.cache.updatecachemiddleware',    'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', 'django.middleware.security.securitymiddleware', 'debug_toolbar.middleware.debugtoolbarmiddleware', 'django.middleware.cache.fetchfromcachemiddleware', ) 

is there way automatically update redis cache?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -