Friday, November 26, 2010

Caching middleware causes default page caching

I have added following to cache some common DB data and it seems it
has started caching whole pages by default. Some pages appeared to be
retrieved from cache without even hitting the view.

I am using
CACHE_BACKEND = 'locmem://'

following middleware in following order

'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',

and in my views,

from django.core.cache import cache
and cache.set('add_key', 'Initial value')
>>> cache.add('add_key', 'New value')
>>> cache.get('add_key')
'Initial value'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment