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:12 +0200
changeset 807 cf45aeb4dd61
parent 806 9a308106275c
child 808 5427a26480ae
Updated cache key when displayed shared content in the context of site root
src/pyams_content/features/header/skin/__init__.py
--- a/src/pyams_content/features/header/skin/__init__.py	Mon Jul 09 11:12:17 2018 +0200
+++ b/src/pyams_content/features/header/skin/__init__.py	Mon Jul 09 11:58:12 2018 +0200
@@ -19,6 +19,7 @@
 
 # import interfaces
 from pyams_content.features.header.interfaces import IHeaderTarget, IHeaderRenderer, IHeaderSettings
+from pyams_content.features.header.skin.interfaces import IHeaderClass
 from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
 from pyams_portal.interfaces import PREVIEW_MODE
 from pyams_skin.layer import IPyAMSLayer
@@ -40,18 +41,27 @@
     """Base header renderer"""
 
     @reify
+    def settings_target(self):
+        context = self.request.annotations.get(DISPLAY_CONTEXT)
+        if context is None:
+            context = self.context
+        return get_parent(context, IHeaderTarget)
+
+    @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, IHeaderTarget)
+        target = self.settings_target
         settings = IHeaderSettings(target)
         while settings.inherit:
             settings = IHeaderSettings(settings.parent)
         return settings.settings
 
+    @property
+    def main_header_class(self):
+        request = self.request
+        return request.registry.queryMultiAdapter((request.context, request), IHeaderClass, default='')
+
     def render(self):
         preview_mode = self.request.annotations.get(PREVIEW_MODE, False)
         if preview_mode:
@@ -60,6 +70,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))