# HG changeset patch # User raph # Date 1271928761 -7200 # Node ID b60ab54b67828eefe5f42392efd0a01d712cc564 # Parent 9075dc2fb93c7d2a915f2f0cbe3b382bef63d98c fix usage of dj caching diff -r 9075dc2fb93c -r b60ab54b6782 src/cm/converters/pandoc_converters.py --- a/src/cm/converters/pandoc_converters.py Tue Apr 20 11:37:33 2010 +0200 +++ b/src/cm/converters/pandoc_converters.py Thu Apr 22 11:32:41 2010 +0200 @@ -1,6 +1,6 @@ # python 2.5 compat from __future__ import with_statement -from cm.utils.cache import memoize +from cm.utils.cache import memoize, dj_memoize ###### ## This module requires pandoc v > 1.0 (pandoc & markdown executables) ###### @@ -37,7 +37,7 @@ _PANDOC_ENCODING = 'utf8' -@memoize +@dj_memoize def pandoc_convert(content, from_format, to_format, full=False, raw=False): """ Convert markdown content to pdf @@ -72,7 +72,7 @@ return content -@memoize +@dj_memoize def do_tidy(content=None, file_name=None): """ Tidy (html) content @@ -109,7 +109,7 @@ if not os.path.isfile(LATEX_HEADER_PATH): raise Exception('LATEX_HEADER_PATH is not a file!') -@memoize +@dj_memoize def pandoc_markdown2pdf(content=None, file_name=None): """ Convert markdown content to pdf @@ -154,7 +154,7 @@ # TODO: manage images in pandoc (?) # TODO: use tidy to cleanup html -@memoize +@dj_memoize def pandoc_pandoc(content, from_format, to_format, full=False, raw=False): """ Convert content (should be unicode) from from_format to to_format diff -r 9075dc2fb93c -r b60ab54b6782 src/cm/utils/cache.py --- a/src/cm/utils/cache.py Tue Apr 20 11:37:33 2010 +0200 +++ b/src/cm/utils/cache.py Thu Apr 22 11:32:41 2010 +0200 @@ -1,9 +1,10 @@ from django.core.cache import cache +from hashlib import sha1 # adapted [to django] from http://code.activestate.com/recipes/325205/ def dj_memoize(f): def g(*args, **kwargs): - key = ( f.__name__, f, tuple(args), frozenset(kwargs.items()) ) + key = sha1( str((f.__name__, f, tuple(args), frozenset(kwargs.items())) )).hexdigest() val = cache.get(key) if not val: val = f(*args, **kwargs)