Thursday, December 29, 2011

Re: CACHE_MIDDLEWARE_ANONYMOUS_ONLY isn't working for me

I did some more experimenting. Perhaps I misunderstood the purpose of
CACHE_MIDDLEWARE_ANONYMOUS_ONLY.

The view in my example below is a simple generic list view, and it did
not interrogate request.user or make any
request.user.is_authenticated() type checks. If I add those checks to
the template, then after I change a model in the admin, I see the view
update with those changes when I am logged in. Unfortunately it also
updates even when I'm not logged in (testing with a 2nd browser).

So unless I am missing something, the usefulness of
CACHE_MIDDLEWARE_ANONYMOUS_ONLY is much more limited than I thought.


On Dec 28, 10:25 am, Brian Neal <bgn...@gmail.com> wrote:
> I have CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True. It seems to cache pages
> even for people who have logged in. For example, I can log into the
> admin, and edit an object. If I then visit the view for that app, my
> changes do not get seen until the 5 minute cache timeout hits.
>
> I suspect my middleware order is not correct, but I have read and re-
> read the docs and I'm still confused.
>
> Here are my cache related settings:
>
> CACHES = {
>     'default': {
>         'BACKEND':
> 'django.core.cache.backends.memcached.MemcachedCache',
>         'LOCATION': '127.0.0.1:11211',
>         'TIMEOUT': 600,
>     },
>
> }
>
> CACHE_MIDDLEWARE_ALIAS = 'default'
> CACHE_MIDDLEWARE_SECONDS = 600
> CACHE_MIDDLEWARE_KEY_PREFIX = 'BNS'
> CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
>
> MIDDLEWARE_CLASSES.insert(0,
> 'django.middleware.cache.UpdateCacheMiddleware')
> MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware ')
>
> Does anyone see anything wrong or have suggestions on how to debug
> this?
>
> Thanks,
> BN

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment