diff --git a/boards/utils.py b/boards/utils.py --- a/boards/utils.py +++ b/boards/utils.py @@ -72,15 +72,20 @@ def get_websocket_token(user_id='', time return token +# TODO Test this carefully def cached_result(key_method=None): """ Caches method result in the Django's cache system, persisted by object name, - object name and model id if object is a Django model. + object name, model id if object is a Django model, args and kwargs if any. """ def _cached_result(function): def inner_func(obj, *args, **kwargs): - # TODO Include method arguments to the cache key cache_key_params = [obj.__class__.__name__, function.__name__] + + cache_key_params += args + for key, value in kwargs: + cache_key_params.append(key + ':' + value) + if isinstance(obj, Model): cache_key_params.append(str(obj.id)) diff --git a/boards/views/authors.py b/boards/views/authors.py --- a/boards/views/authors.py +++ b/boards/views/authors.py @@ -4,6 +4,7 @@ from django.shortcuts import render import neboard from boards.authors import authors +from boards.utils import cached_result from boards.views.base import BaseBoardView from boards.models import Post @@ -23,6 +24,7 @@ class AuthorsView(BaseBoardView): return render(request, 'boards/authors.html', params) + @cached_result() def _get_directory_size(self, directory): total_size = 0 for dirpath, dirnames, filenames in os.walk(directory):