I’m getting some weeeeeeird behavior with my cache in django. If I refresh the page, I get the same value over and over(which is an int that’s supposed to get incremented every time the view gets hit). But, if I login in another browser with the same username/passwd, I see an incremented number, but it doesn’t increment until I log in again. I never logged out either, just left the page open and logged in from another browser.
Edit: It also increments every time I change the url(e.g. add a slash to stay in same view) Browser cache is supposedly disabled.
Edit 2: Now super weird: it started working on every refresh when I opened a new page in another browser after adding the @never_cache decorator to my view, but then when i switched back to apache/wsgi, it stopped working again (yes, i restarted apache).
Edit 3: Randomly started working under apache now… but in chrome if i set the url to have the trailing /, it goes back to the number it was before x refreshes. But, if I refresh in chromium with trailing /, it keeps incrementing. Would this be a browser or apache cache?
View code:
from django.core.cache import cache
if cache.get('counter') != None:#0 needs to let this pass
cache.incr('counter')
else:
cache.set('counter', 0)
return HttpResponse(cache.get('counter'))
Relevant settings:
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware', #cache middleware
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',) #cache middleware
CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
CACHES = {'default':{
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211', #this is the default port for memcache
'TIMEOUT': '1800' #30 Minutes
}
}
I’ll be closely monitoring this question for any requests for more info about my problem, so comments will get answered quickly.

In your
MIDDLEWARE_CLASSESyou havedjango.middleware.cache.UpdateCacheMiddlewareanddjango.middleware.cache.FetchFromCacheMiddlewarewhich are for page caching. That’s why you saw the behavior go away when you used the@never_cachedecorator.You may have been seeing the weird slash/no-slash problem because those pages were still in the cache(I’m not 100% sure if the decorator interacts with the fetching from cache part).
If you flush your cache, or even take the middlewares out for testing, and try again, I’d bet you would see a consistent incrementing that you expect.