Ticket #7460: cachetag.diff

File cachetag.diff, 1.2 KB (added by Julian Bez, 16 years ago)
  • django/templatetags/cache.py

     
    55
    66register = Library()
    77
     8def build_cache_key(*fragments):
     9    """
     10    Generates an unique key for every unique set of arguments
     11    """
     12    key = u":".join(fragments)
     13    return key.replace("%", "%25").replace(" ", "%20")
     14
    815class CacheNode(Node):
    916    def __init__(self, nodelist, expire_time_var, fragment_name, vary_on):
    1017        self.nodelist = nodelist
     
    2229        except (ValueError, TypeError):
    2330            raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
    2431        # Build a unicode key for this fragment and all vary-on's.
    25         cache_key = u':'.join([self.fragment_name] + [force_unicode(resolve_variable(var, context)) for var in self.vary_on])
     32        cache_key = build_cache_key(self.fragment_name, *[force_unicode(resolve_variable(var, context)) for var in self.vary_on])
    2633        value = cache.get(cache_key)
    2734        if value is None:
    2835            value = self.nodelist.render(context)
Back to Top