Added cached_function decorator for comfortable caching of expensive functions.
Now relies on Django, but the Python-only code could be split.