6

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 = '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.

Belmin Fernandez
  • 8,307
  • 9
  • 51
  • 75
  • 1
    Have you tried connecting to the memcache instance and checking to see if anything is cached? It appears like you're doing the right thing, provided you're using django 1.3 – Josh Smeaton Feb 07 '11 at 12:04
  • Yes. I see set's and get's. Anything specifically that I should look at? – Belmin Fernandez Feb 07 '11 at 23:58
  • Beaming, did you find a reason why it did not work for you? Having similar problem with website recently upgraded from django 1.2. – bmihelac Nov 27 '11 at 19:15
  • Same issue here. Did anyone figure this out? – Nathan Feb 29 '12 at 21:37
  • I never did figure this one out. I have unmarked it as answered. Albeit, I am no longer working on this issue so I wouldn't know how to confirm whether an answer addresses it. – Belmin Fernandez Feb 29 '12 at 22:15
  • In my case, this was due to a [combination of sessions and google analytics](http://python.6.n6.nabble.com/The-state-of-per-site-per-view-middleware-caching-in-Django-td486447.html). With the google tracker commented out the cache is working. – Nathan Mar 01 '12 at 15:50

1 Answers1

0

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.

Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
  • Yes. I know that and have confirmed that the `request.GET` and `request.POST` are empty. This one has me stumped but I've put it on the backburner for the time being and will investigate it sometime next week. – Belmin Fernandez Feb 09 '11 at 23:40