Ticket #16499: loader.py.diff

File loader.py.diff, 850 bytes (added by blacktear23, 4 years ago)

Add template cache

  • loader.py

     
    3131from django.conf import settings
    3232
    3333template_source_loaders = None
     34template_cache = {}
    3435
    3536class BaseLoader(object):
    3637    is_usable = False
     
    151152
    152153def get_template(template_name):
    153154    """
     155    Improve load template performance, add a template cache for load
     156    template.
     157    """
     158    global template_cache
     159    if template_cache.has_key(template_name):
     160        return template_cache[template_name]
     161    else:
     162        template = do_get_template(template_name)
     163        template_cache[template_name] = template
     164        return template
     165
     166def do_get_template(template_name):
     167    """
    154168    Returns a compiled Template object for the given template name,
    155169    handling template inheritance recursively.
    156170    """
Back to Top