Use hostname in portlets cache key
authorThierry Florac <thierry.florac@onf.fr>
Tue, 23 Oct 2018 10:47:36 +0200
changeset 209 0b7d87141afa
parent 208 b6733706f70a
child 210 8c92bf83518d
Use hostname in portlets cache key
src/pyams_portal/portlet.py
--- a/src/pyams_portal/portlet.py	Wed Oct 17 16:05:20 2018 +0200
+++ b/src/pyams_portal/portlet.py	Tue Oct 23 10:47:36 2018 +0200
@@ -12,43 +12,37 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
 import logging
 logger = logging.getLogger('PyAMS (portal)')
 
 import venusian
-
-# import interfaces
-from pyams_form.interfaces.form import IFormContextPermissionChecker
-from pyams_portal.interfaces import IPortlet, IPortletSettings, IPortletConfiguration, IPortletPreviewer, \
-    IPortletRenderer, IPortalPortletsConfiguration, IPortalTemplate, IPortalContext, IPortalPage, \
-    IPortalTemplateConfiguration, MANAGE_TEMPLATE_PERMISSION, IPortletRendererSettings, PORTLET_RENDERER_SETTINGS_KEY, \
-    PREVIEW_MODE
-from pyams_utils.interfaces import ICacheKeyValue
-from pyams_utils.interfaces.url import DISPLAY_CONTEXT
-from zope.traversing.interfaces import ITraversable
-
-# import packages
 from persistent import Persistent
 from persistent.mapping import PersistentMapping
-from pyams_cache.beaker import get_cache
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_adapter_weight, get_annotation_adapter
-from pyams_utils.factory import get_object_factory, is_interface
-from pyams_utils.registry import get_global_registry
-from pyams_utils.request import check_request
-from pyams_utils.vocabulary import vocabulary_config
-from pyams_viewlet.viewlet import ViewContentProvider
 from pyramid.exceptions import ConfigurationError
 from pyramid.renderers import render
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
 from zope.copy import clone
-from zope.interface import implementer, alsoProvides, noLongerProvides
+from zope.interface import alsoProvides, implementer, noLongerProvides
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
+from zope.traversing.interfaces import ITraversable
+
+from pyams_cache.beaker import get_cache
+from pyams_form.interfaces.form import IFormContextPermissionChecker
+from pyams_portal.interfaces import IPortalContext, IPortalPage, IPortalPortletsConfiguration, IPortalTemplate, \
+    IPortalTemplateConfiguration, IPortlet, IPortletConfiguration, IPortletPreviewer, IPortletRenderer, \
+    IPortletRendererSettings, IPortletSettings, MANAGE_TEMPLATE_PERMISSION, PORTLET_RENDERER_SETTINGS_KEY, PREVIEW_MODE
+from pyams_utils.adapter import ContextAdapter, adapter_config, get_adapter_weight, get_annotation_adapter
+from pyams_utils.factory import get_object_factory, is_interface
+from pyams_utils.interfaces import ICacheKeyValue
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
+from pyams_utils.registry import get_global_registry
+from pyams_utils.request import check_request
+from pyams_utils.vocabulary import vocabulary_config
+from pyams_viewlet.viewlet import ViewContentProvider
 
 
 #
@@ -171,8 +165,8 @@
 PORTLETS_CACHE_REGION = 'portlets'
 PORTLETS_CACHE_NAME = 'PyAMS::portlet'
 
-PORTLETS_CACHE_KEY = 'portlet::{portlet}::{context}::{lang}'
-PORTLETS_CACHE_DISPLAY_CONTEXT_KEY = 'portlet::{portlet}::{context}::{display}::{lang}'
+PORTLETS_CACHE_KEY = 'portlet::{hostname}::{portlet}::{context}::{lang}'
+PORTLETS_CACHE_DISPLAY_CONTEXT_KEY = 'portlet::{hostname}::{portlet}::{context}::{display}::{lang}'
 
 
 @implementer(IPortletRenderer)
@@ -219,10 +213,12 @@
             display_context = self.request.annotations.get(DISPLAY_CONTEXT)
             if display_context is None:
                 cache_key = PORTLETS_CACHE_KEY.format(portlet=ICacheKeyValue(self.settings),
+                                                      hostname=self.request.host,
                                                       context=ICacheKeyValue(self.context),
                                                       lang=self.request.locale_name)
             else:
                 cache_key = PORTLETS_CACHE_DISPLAY_CONTEXT_KEY.format(portlet=ICacheKeyValue(self.settings),
+                                                                      hostname=self.request.host,
                                                                       context=ICacheKeyValue(self.context),
                                                                       display=ICacheKeyValue(display_context),
                                                                       lang=self.request.locale_name)