On Mar 3, 2009, at 6:20 PM, davathar wrote:

> Ok, so I'm sure that I violated DRY and probably a few other good
> programming principles, but here's what I did that worked and doesn't
> alter the source.  It's a hack, but I'm still learning.
>
> I created a new monkey_patches.py file and copied the function from
> the core file and altered it.  Now I just call @really_never_cache
> instead.
>
> try:
>    from functools import wraps
> except ImportError:
>    from django.utils.functional import wraps  # Python 2.3, 2.4
> fallback.
>
> from django.utils.decorators import decorator_from_middleware
> from django.utils.cache import patch_cache_control,
> add_never_cache_headers
> from django.middleware.cache import CacheMiddleware
>
> def really_never_cache(view_func):
>    """
>    Replacement Decorator for never_cache that adds a few more headers
>    to a response so that it will never be cached.
>    """
>    def _wrapped_view_func(request, *args, **kwargs):
>        response = view_func(request, *args, **kwargs)
>        add_never_cache_headers(response)
>        response['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
>        response['Pragma'] = 'no-cache'
>        response['Cache-Control'] = 'no-cache, no-store, max-age=0,
> must-revalidate'
>        return response
>    return wraps(view_func)(_wrapped_view_func)



Note that "no-store" or "no-cache" in combination with HTTPS is known  
to be buggy in some IE browsers, primarily for file downloads.  If a  
non-buggy HTTPS is desired, you should be able to get nearly the same  
non-caching result with "max-age=0, private, must-revalidate".

'max-age=0' means cached entries are always stale.

'private' means it will never get stored in conforming shared caches  
-- essentially equivalent to 'no-store' for shared caches.  HTTPS-only  
gives the same result.

'must-revalidate' in this case means that conforming browsers must  
always revalidate stale entries which theoretically should mean a new  
fresh request with each display (a conditional request if Last- 
Modified or Etag is also set), although I haven't tested this behavior  
with Firefox history browsing using the back button.

Note, if you're using the Firebug extension, you might want to turn it  
off when testing browser cache revalidate behavior as it messes with  
some of this.

Ric



--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to