django-planet
Jan. 31, 2006

Template + Cache = Crazy Delicious

in blog Jacob Kaplan-Moss
original entry Template + Cache = Crazy Delicious

Here’s a simple class for a template tag that caches its output (with apologies to Chris Parnell and Andy Samberg): from django.core import template from django.core.cache import cache from django.conf.settings import DEBUG class CachedNode(template.Node): """ Cached template node. Subclasses should define the methods get_cache_key() and get_content() instead of the standard render() method. Subclasses may also define the class attribute cache_timeout to override the default cache timeout of ten minutes. """ cache_timeout = 600 def render(self, context): if DEBUG: return self.