Ticket #16892: class-based-view-caching.diff

File class-based-view-caching.diff, 1.5 KB (added by rob@…, 13 years ago)

class based cache settings patch

  • django/middleware/cache.py

    diff --git a/django/middleware/cache.py b/django/middleware/cache.py
    index 34bf0ca..b7f27b3 100644
    a b class UpdateCacheMiddleware(object):  
    6969        self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
    7070        self.cache = get_cache(self.cache_alias)
    7171
     72    def process_view(self, request, view_func, view_args, view_kwargs):
     73        if hasattr(view_func, '__cbvclass__') and hasattr(view_func.__cbvclass__, 'cache_timeout'):
     74            request.cache_timeout = view_func.__cbvclass__.cache_timeout
     75
    7276    def _session_accessed(self, request):
    7377        try:
    7478            return request.session.accessed
    class UpdateCacheMiddleware(object):  
    100104        # length.
    101105        timeout = get_max_age(response)
    102106        if timeout == None:
    103             timeout = self.cache_timeout
     107            timeout = getattr(request, 'cache_timeout', self.cache_timeout)
    104108        elif timeout == 0:
    105109            # max-age was set to 0, don't bother caching.
    106110            return response
  • django/views/generic/base.py

    diff --git a/django/views/generic/base.py b/django/views/generic/base.py
    index f2d4950..42191af 100644
    a b class View(object):  
    5151        # and possible attributes set by decorators
    5252        # like csrf_exempt from dispatch
    5353        update_wrapper(view, cls.dispatch, assigned=())
     54
     55        # and a reference back to the class
     56        view.__cbvclass__ = cls
     57
    5458        return view
    5559
    5660    def dispatch(self, request, *args, **kwargs):
Back to Top