Updated cache key when displayed shared content in the context of site root
authorThierry Florac <thierry.florac@onf.fr>
Mon, 09 Jul 2018 11:58:42 +0200
changeset 809 efdeebb63567
parent 808 5427a26480ae
child 810 7b5d910b2205
Updated cache key when displayed shared content in the context of site root
src/pyams_content/features/footer/skin/__init__.py
--- a/src/pyams_content/features/footer/skin/__init__.py	Mon Jul 09 11:58:23 2018 +0200
+++ b/src/pyams_content/features/footer/skin/__init__.py	Mon Jul 09 11:58:42 2018 +0200
@@ -40,13 +40,17 @@
     """Base footer renderer"""
 
     @reify
+    def settings_target(self):
+        context = self.request.annotations.get(DISPLAY_CONTEXT)
+        if context is None:
+            context = self.context
+        return get_parent(context, IFooterTarget)
+
+    @reify
     def settings(self):
         if self.settings_interface is None:
             return None
-        context = self.request.annotations.get(DISPLAY_CONTEXT)
-        if context is None:
-            context = self.context
-        target = get_parent(context, IFooterTarget)
+        target = self.settings_target
         settings = IFooterSettings(target)
         while settings.inherit:
             settings = IFooterSettings(settings.parent)
@@ -60,6 +64,8 @@
             portlets_cache = get_cache(PORTLETS_CACHE_REGION, PORTLETS_CACHE_NAME)
             cache_key = PORTLETS_CACHE_KEY.format(portlet=self.name,
                                                   context=ICacheKeyValue(self.settings))
+            if self.context is not self.request.context:  # display shared content
+                cache_key = '{0}::shared'.format(cache_key)
             try:
                 result = portlets_cache.get_value(cache_key)
                 logger.debug("Retrieving header content from cache key {0}".format(cache_key))