Django

Code

Changeset 809

Show
Ignore:
Timestamp:
10/08/05 19:37:56 (3 years ago)
Author:
adrian
Message:

Moved vary decorators from django.utils.cache to django.views.decorators.vary

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/cache.py

    r808 r809  
    11""" 
    2 This module contains helper functions and decorators for controlling caching. 
    3 It does so by managing the "Vary" header of responses. It includes functions 
    4 to patch the header of response objects directly and decorators that change 
    5 functions to do that header-patching themselves. 
     2This module contains helper functions for controlling caching. It does so by 
     3managing the "Vary" header of responses. It includes functions to patch the 
     4header of response objects directly and decorators that change functions to do 
     5that header-patching themselves. 
    66 
    77For information on the Vary header, see: 
     
    6565    response['Vary'] = ', '.join(vary) 
    6666 
    67 def vary_on_headers(*headers): 
    68     """ 
    69     A view decorator that adds the specified headers to the Vary header of the 
    70     response. Usage: 
    71  
    72        @vary_on_headers('Cookie', 'Accept-language') 
    73        def index(request): 
    74            ... 
    75  
    76     Note that the header names are not case-sensitive. 
    77     """ 
    78     def decorator(func): 
    79         def inner_func(*args, **kwargs): 
    80             response = func(*args, **kwargs) 
    81             patch_vary_headers(response, headers) 
    82             return response 
    83         return inner_func 
    84     return decorator 
    85  
    86 def vary_on_cookie(func): 
    87     """ 
    88     A view decorator that adds "Cookie" to the Vary header of a response. This 
    89     indicates that a page's contents depends on cookies. Usage: 
    90  
    91         @vary_on_cookie 
    92         def index(request): 
    93             ... 
    94     """ 
    95     def inner_func(*args, **kwargs): 
    96         response = func(*args, **kwargs) 
    97         patch_vary_headers(response, ('Cookie',)) 
    98         return response 
    99     return inner_func 
    100  
    10167def _generate_cache_key(request, headerlist, key_prefix): 
    10268    "Returns a cache key from the headers given in the header list."