Ticket #6262: cache_templates.diff
File cache_templates.diff, 3.3 KB (added by , 17 years ago) |
---|
-
home/chris/django/trunk/django/conf/global_settings.py
157 157 # 'django.core.context_processors.request', 158 158 ) 159 159 160 # Number of seconds to cache templates retreived using the 161 # django.template.loader get_template method (0 means no caching). 162 # Templates are only cached if DEBUG is False. 163 CACHE_TEMPLATES = 600 164 160 165 # Output to use in template system for invalid (e.g. misspelled) variables. 161 166 TEMPLATE_STRING_IF_INVALID = '' 162 167 -
home/chris/django/trunk/django/template/loader.py
21 21 # installed, because pkg_resources is necessary to read eggs. 22 22 23 23 from django.core.exceptions import ImproperlyConfigured 24 from django.core.cache import cache 24 25 from django.template import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins 25 26 from django.conf import settings 26 27 … … 75 76 """ 76 77 Returns a compiled Template object for the given template name, 77 78 handling template inheritance recursively. 79 80 If settings.DEBUG is False, settings.CACHE_TEMPLATES is non-zero and the 81 template source is found, then the compiled template is cached. 78 82 """ 83 if settings.DEBUG: 84 cache_template_duration = 0 85 else: 86 cache_template_duration = settings.CACHE_TEMPLATES 87 if cache_template_duration: 88 # Try to retreive the template from cache before looking through 89 # template_source_loaders for it. 90 cache_name = 'django.template.loader.%s' % template_name 91 template = cache.get(cache_name) 92 if template: 93 return template 94 elif template == 0: 95 # This template couldn't be pickled, don't try again. 96 cache_template_duration = 0 79 97 source, origin = find_template_source(template_name) 80 98 template = get_template_from_string(source, origin, template_name) 99 if cache_template_duration: 100 try: 101 cache.set(cache_name, template, cache_template_duration) 102 except TypeError: 103 # Template couldn't be pickled, most likely because of an decorated 104 # filter (Python 2.3 can't pickle any filter decorated with 105 # stringfilter). 106 cache.set(cache_name, 0, cache_template_duration) 81 107 return template 82 108 83 109 def get_template_from_string(source, origin=None, name=None): -
home/chris/django/trunk/docs/settings.txt
269 269 The default number of seconds to cache a page when the caching middleware or 270 270 ``cache_page()`` decorator is used. 271 271 272 CACHE_TEMPLATES 273 --------------- 274 275 Default: ``600`` 276 277 The number of seconds to cache a template loaded and compiled from the file 278 system. 279 280 Note that Django will only cache templates if ``DEBUG`` is ``False``. 281 282 See also ``DEBUG``. 283 272 284 DATABASE_ENGINE 273 285 --------------- 274 286