Why doesn't Django's per-site cache middleware work for me?
I am using Django 1.3 beta 1 and set up memcached. I made changes to my settings.py
per Django's instructions:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': '127.0.0.1:11211',
}
}
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
)
CACHE_MIDDLEWARE_SECONDS = 100000
CACHE_MIDDLEWARE_KEY_PREFIX开发者_如何学C = 'site_cache'
This is the test view function I'm hitting:
def home(request):
print 'uncached'
# ...View's code...
I always get uncached
printed on the development server's output and I always get hits to the database. Why? Am I missing something or just misunderstanding caching completely?
Edit #1:
Template fragment caching works perfectly fine. Am I just missing something? Please help.
It appears that you have everything set up correctly. The only possible caveat I can see in the documentation is the following:
The cache middleware caches every page that doesn't have GET or POST parameters.
Unfortunately, I'm assuming you already know this and it won't help you.
精彩评论