@register.tag('cache')
def do_cache(parser, token):
 nodelist = parser.parse(('endcache',))
 parser.delete_first_token()
 tokens = token.split_contents()
 if (len(tokens) < 3):
  raise TemplateSyntaxError(("'%r' tag requires at least 2 arguments." % tokens[0]))
 if ((len(tokens) > 3) and tokens[(-1)].startswith('using=')):
  cache_name = parser.compile_filter(tokens[(-1)][len('using='):])
  tokens = tokens[:(-1)]
 else:
  cache_name = None
 return CacheNode(nodelist, parser.compile_filter(tokens[1]), tokens[2], [parser.compile_filter(t) for t in tokens[3:]], cache_name)

@ register . tag ( 'cache' ) def do_cache ( parser , token ) : nodelist = parser . parse ( ( 'endcache' , ) ) parser . delete_first_token ( ) tokens = token . split_contents ( ) if ( len ( tokens ) < 3 ) : raise TemplateSyntaxError ( ( "'%r' tag requires at least 2 arguments." % tokens [ 0 ] ) ) if ( ( len ( tokens ) > 3 ) and tokens [ ( - 1 ) ] . startswith ( 'using=' ) ) : cache_name = parser . compile_filter ( tokens [ ( - 1 ) ] [ len ( 'using=' ) : ] ) tokens = tokens [ : ( - 1 ) ] else : cache_name = None return CacheNode ( nodelist , parser . compile_filter ( tokens [ 1 ] ) , tokens [ 2 ] , [ parser . compile_filter ( t ) for t in tokens [ 3 : ] ] , cache_name )
this will cache the contents of a template fragment for a given amount of time .