Use locale name in request cache key
authorThierry Florac <thierry.florac@onf.fr>
Thu, 19 Jul 2018 16:45:53 +0200
changeset 154 0734dda7bc82
parent 153 8dc4a35478d4
child 155 901845e10a37
Use locale name in request cache key
src/pyams_portal/portlet.py
--- a/src/pyams_portal/portlet.py	Fri Jul 13 16:46:41 2018 +0200
+++ b/src/pyams_portal/portlet.py	Thu Jul 19 16:45:53 2018 +0200
@@ -170,8 +170,8 @@
 PORTLETS_CACHE_REGION = 'portlets'
 PORTLETS_CACHE_NAME = 'PyAMS::portlet'
 
-PORTLETS_CACHE_KEY = 'portlet::{portlet}::{context}'
-PORTLETS_CACHE_DISPLAY_CONTEXT_KEY = 'portlet::{portlet}::{context}::{display}'
+PORTLETS_CACHE_KEY = 'portlet::{portlet}::{context}::{lang}'
+PORTLETS_CACHE_DISPLAY_CONTEXT_KEY = 'portlet::{portlet}::{context}::{display}::{lang}'
 
 
 @implementer(IPortletRenderer)
@@ -218,11 +218,13 @@
             display_context = self.request.annotations.get(DISPLAY_CONTEXT)
             if display_context is None:
                 cache_key = PORTLETS_CACHE_KEY.format(portlet=ICacheKeyValue(self.settings),
-                                                      context=ICacheKeyValue(self.context))
+                                                      context=ICacheKeyValue(self.context),
+                                                      lang=self.request.locale_name)
             else:
                 cache_key = PORTLETS_CACHE_DISPLAY_CONTEXT_KEY.format(portlet=ICacheKeyValue(self.settings),
                                                                       context=ICacheKeyValue(self.context),
-                                                                      display=ICacheKeyValue(display_context))
+                                                                      display=ICacheKeyValue(display_context),
+                                                                      lang=self.request.locale_name)
             if self.use_authentication:
                 cache_key = '{0}::{1}'.format(cache_key, self.request.principal.id)
             # load rendered content from cache, or create output and store it in cache