Ask Your Question
0

How do I configure memcached for Django 1.3?

asked 2012-07-24 23:25:23 -0600

Joseph gravatar image

The default caching doesn't work. (There are numerous issues due to it.)

memcached is recommended. However, the settings.py is for Django <= 1.2 caching.

How do you configure memcached for Django 1.3?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-07-24 23:27:17 -0600

Joseph gravatar image

updated 2012-07-26 12:40:22 -0600

[I will update these instructions if Evgeny tells me otherwise.]

Follow the memcache setup instructions described here: http://docs.webfaction.com/software/memcached.html and make sure python-memcached is installed.

Then, put the following in your settings.py:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': 'unix:/home/USERNAME/memcached.sock',
        'TIMEOUT': 18000,
        'KEY_PREFIX': 'askbot',
    }
}
CACHE_TIMEOUT = 18000
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

And disable the current CACHE_BACKEND. (The second CACHE_TIMEOUT is necessary because of a small bug.)

Also, disable the following middleware:

'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',

Otherwise you will get errors, like entire pages being cached when they shouldn't.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-07-24 23:25:23 -0600

Seen: 411 times

Last updated: Jul 26 '12