From c4e64669264c981efde3118457faa277196eff62 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 25 Oct 2012 15:17:25 +0200 Subject: [PATCH] Added cache for the ajax-version of the projector --- openslides/openslides_global_settings.py | 7 +++++++ openslides/projector/api.py | 3 +++ openslides/projector/views.py | 18 ++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/openslides/openslides_global_settings.py b/openslides/openslides_global_settings.py index 5d3348e9c..6b0417b0d 100644 --- a/openslides/openslides_global_settings.py +++ b/openslides/openslides_global_settings.py @@ -134,3 +134,10 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'openslides.utils.utils.revision', 'openslides.utils.auth.anonymous_context_additions', ) + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + 'LOCATION': 'openslidecache' + } +} diff --git a/openslides/projector/api.py b/openslides/projector/api.py index 56fe4e0d4..de0cf03b8 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -11,6 +11,7 @@ """ from django.conf import settings +from django.core.cache import cache from django.template.loader import render_to_string from django.utils.datastructures import SortedDict from django.utils.importlib import import_module @@ -85,6 +86,8 @@ def set_active_slide(sid, argument=None): """ config["presentation"] = sid config['presentation_argument'] = argument + cache.delete('projector_content') + cache.delete('projector_scrollcontent') def register_slidemodel(model, model_name=None, control_template=None, diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 6a71ad637..54fa7a866 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -15,6 +15,7 @@ from time import time from django.conf import settings from django.contrib import messages +from django.core.cache import cache from django.core.context_processors import csrf from django.core.urlresolvers import reverse from django.db import transaction @@ -107,10 +108,19 @@ class Projector(TemplateView, AjaxMixin): return context def get_ajax_context(self, **kwargs): - content = render_block_to_string(self.get_template_names()[0], - 'content', self.data) - scrollcontent = render_block_to_string(self.get_template_names()[0], - 'scrollcontent', self.data) + content = cache.get('projector_content') + if not content: + content = render_block_to_string( + self.get_template_names()[0], + 'content', self.data) + cache.set('projector_content', content) + + scrollcontent = cache.get('projector_scrollcontent') + if not scrollcontent: + scrollcontent = render_block_to_string( + self.get_template_names()[0], + 'scrollcontent', self.data) + cache.set('projector_scrollcontent', scrollcontent) context = super(Projector, self).get_ajax_context(**kwargs) content_hash = hash(content)