First time here? Check out the FAQ!
1

What is wrong with this cache setup?

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

kovszilard's avatar
21
kovszilard
asked 2015-05-07 04:23:51 -0500, updated 2015-05-07 04:32:04 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

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',

)

kovszilard's avatar
21
kovszilard
answered 2015-05-07 09:44:59 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments