Ask Your Question
1

What is wrong with this cache setup?

asked 2015-05-07 04:23:51 -0600

kovszilard gravatar image

updated 2015-05-07 04:32:04 -0600

I have a problem with memcached setup. When i visit some pages anonymously everything works as expected, but after logging in all the previously visited pages looks like before authentication. This happens for example with /questions and the /users page. (I'm using ldap authentication, not sure if it has anything to do with this problem)

After clearing the cache by hand like this:

python manage.py shell
>>> from django.core.cache import cache
>>> cache.clear()

everything works perfectly.

here is the caching related part from my settings.py:

MIDDLEWARE_CLASSES = (
    ...
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    ...
)

CACHES = {
    'default': {
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
            'LOCATION': '127.0.0.1:11211',
            'TIMEOUT': 60,
            'KEY_PREFIX': 'askbot',
    }
}

CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

The intresting thing that even the 60 second cache period is over, I still get this pages from cache and the sign out link doesn't show up on top of the page.

some version numbers: askbot: 0.7.53, Python 2.6.6, Memcached 1.4.4, RedHatEnterpriseServer 6.5

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-05-07 09:44:59 -0600

kovszilard gravatar image

According to django's documentation, there was a problem with Middleware ordering https://docs.djangoproject.com/en/1.8/ref/middleware/#middleware-ordering (link to doc)

Here is my working middleware config:

MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
#'django.middleware.gzip.GZipMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
## Enable the following middleware if you want to enable
## language selection in the site settings.
#'askbot.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
#'django.middleware.sqlprint.SqlPrintingMiddleware',

#below is askbot stuff for this tuple
'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
'askbot.middleware.forum_mode.ForumModeMiddleware',
'askbot.middleware.cancel.CancelActionMiddleware',
'django.middleware.transaction.TransactionMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
'askbot.middleware.view_log.ViewLogMiddleware',
'askbot.middleware.spaceless.SpacelessMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',

)

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

Stats

Asked: 2015-05-07 04:23:51 -0600

Seen: 2,842 times

Last updated: May 07 '15