From f0d27a7f860fd09f1ec40f942b196beeb412c6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 17 Apr 2015 21:50:49 +0200 Subject: [PATCH] add methods to know if there's something in cache (#6977) --- src/cmsplugin_blurp/renderers/data_source.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cmsplugin_blurp/renderers/data_source.py b/src/cmsplugin_blurp/renderers/data_source.py index 8b6d88c..5d1fb42 100644 --- a/src/cmsplugin_blurp/renderers/data_source.py +++ b/src/cmsplugin_blurp/renderers/data_source.py @@ -90,6 +90,14 @@ class Renderer(template.TemplateRenderer): if settings.TEMPLATE_DEBUG: yield 'blurp_debug__', '\n'.join(self.debug_content(context)) + def has_cached_content(self, context): + for source in self.config['sources']: + slug = '{0}.{1}'.format(self.slug, source['slug']) + data = Data(slug, self.config, source, context) + if not data.has_cached_content(): + return False + return True + def debug_content(self, context): try: yield u'config: {0}'.format(pprint.pformat(self.config)) @@ -319,6 +327,10 @@ class Data(object): UPDATE_THREADS = {} CONDITIONS = {} + def has_cached_content(self): + self.__content, until = cache.get(self.key, (self.__CACHE_SENTINEL, None)) + return self.__content is not self.__CACHE_SENTINEL + def get_content(self): if self.__content is not self.__CACHE_SENTINEL: return self.__content