mar 14
Szablony z memcache
Zrobiłem sobie takie coś — mechanizm ładowania szablonów dla Jinja 2, który trzyma zawartość szablonu w memcache i w razie czego ładuje go z pamięci.
class CachedFileSystemLoader(FileSystemLoader):
def get_source(self, environment, template):
key = 'template:%s.%s' % (template, os.environ['CURRENT_VERSION_ID'])
contents = memcache.get(key)
if contents is None:
contents, filename, uptodate = \
super(CachedFileSystemLoader, self).get_source(environment, template)
memcache.set(key, contents, 60*60*24)
else:
pieces = split_template_path(template)
filename = os.path.join(self.searchpath[0], *pieces)
uptodate = lambda: True
return contents, filename, uptodate
Jak na razie działa.