django-orchestra-test/orchestra/utils/functional.py

10 lines
297 B
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
def cached(func):
""" caches func return value """
def cached_func(self, *args, **kwargs):
attr = '_cached_' + func.__name__
if not hasattr(self, attr):
setattr(self, attr, func(self, *args, **kwargs))
return getattr(self, attr)
return cached_func