Ticket #1015: 1015.diff

File 1015.diff, 4.1 KB (added by Gary Wilson <gary.wilson@…>, 18 years ago)
  • django/conf/global_settings.py

    === modified file 'django/conf/global_settings.py'
     
    275275# possible values.
    276276CACHE_BACKEND = 'simple://'
    277277CACHE_MIDDLEWARE_KEY_PREFIX = ''
     278CACHE_MIDDLEWARE_SECONDS = 60 * 10
    278279
    279280####################
    280281# COMMENTS         #
  • django/utils/decorators.py

    === modified file 'django/utils/decorators.py'
     
    11"Functions that help with dynamically creating decorators for views."
    22
    3 def decorator_from_middleware(middleware_class):
    4     """
    5     Given a middleware class (not an instance), returns a view decorator. This
    6     lets you use middleware functionality on a per-view basis.
    7     """
    8     def _decorator_from_middleware(view_func, *args, **kwargs):
    9         middleware = middleware_class(*args, **kwargs)
     3def make_decorator_from_middleware(middleware_class, *deco_args,
     4                                   **deco_kwargs):
     5    """
     6    A decorator factory that returns a decorator from a middleware class.
     7    """
     8    def _decorator_from_middleware(view_func):
     9        middleware = middleware_class(*deco_args, **deco_kwargs)
    1010        def _wrapped_view(request, *args, **kwargs):
    1111            if hasattr(middleware, 'process_request'):
    1212                result = middleware.process_request(request)
     
    3131            return response
    3232        return _wrapped_view
    3333    return _decorator_from_middleware
     34
     35def decorator_from_middleware(middleware_class):
     36    """
     37    Given a middleware class (not an instance), returns a view decorator. This
     38    lets you use middleware functionality on a per-view basis.
     39    """
     40    return make_decorator_from_middleware(middleware_class)
     41
     42def decorator_with_arguments_from_middleware(middleware_class):
     43    """
     44    Given a middleware class (not an instance), return a function that,
     45    when called, returns a view decorator.  This lets you use middleware
     46    functionality on a per-view basis for middleware classes whose
     47    contructors take arguments.
     48    """
     49    def _decorator_factory(*deco_args, **deco_kwargs):
     50        return make_decorator_from_middleware(middleware_class, *deco_args,
     51                                              **deco_kwargs)
     52    return _decorator_factory
  • django/views/decorators/cache.py

    === modified file 'django/views/decorators/cache.py'
     
    1111account on caching -- just like the middleware does.
    1212"""
    1313
    14 from django.utils.decorators import decorator_from_middleware
     14from django.utils.decorators import decorator_with_arguments_from_middleware
    1515from django.utils.cache import patch_cache_control, add_never_cache_headers
    1616from django.middleware.cache import CacheMiddleware
    1717
    18 cache_page = decorator_from_middleware(CacheMiddleware)
     18cache_page = decorator_with_arguments_from_middleware(CacheMiddleware)
    1919
    2020def cache_control(**kwargs):
    2121
  • docs/cache.txt

    === modified file 'docs/cache.txt'
     
    274274    def slashdot_this(request):
    275275        ...
    276276
    277     slashdot_this = cache_page(slashdot_this, 60 * 15)
     277    slashdot_this = cache_page(60 * 15)(slashdot_this)
    278278
    279279Or, using Python 2.4's decorator syntax::
    280280
     
    282282    def slashdot_this(request):
    283283        ...
    284284
    285 ``cache_page`` takes a single argument: the cache timeout, in seconds. In the
     285``cache_page`` can be passed the following optional arguments:
     286 * ``cache_timeout`` - the cache timeout in seconds.  Defaults to
     287   ``settings.CACHE_MIDDLEWARE_SECONDS``, which defaults to 600 seconds
     288   (10 minutes).
     289 * ``key_prefix`` - the prefix to use for cache keys.  Defaults to
     290   ``settings.CACHE_MIDDLEWARE_KEY_PREFIX``, which defaults to ``''``.
     291 * ``cache_anonymous_only`` - if True, only cache anonymous requests. Defaults
     292   to ``setings.CACHE_MIDDLEWARE_ANONYMOUS_ONLY``.
    286293above example, the result of the ``slashdot_this()`` view will be cached for 15
    287294minutes.
    288295
Back to Top