Use ICacheKeyValue interface to get view's cache key
authorThierry Florac <thierry.florac@onf.fr>
Thu, 21 Jun 2018 16:35:00 +0200
changeset 724 2f25e871eea1
parent 723 d4b00aa0a9e0
child 725 ff35457b30a6
Use ICacheKeyValue interface to get view's cache key
src/pyams_content/shared/view/__init__.py
--- a/src/pyams_content/shared/view/__init__.py	Thu Jun 21 11:17:01 2018 +0200
+++ b/src/pyams_content/shared/view/__init__.py	Thu Jun 21 16:35:00 2018 +0200
@@ -25,6 +25,7 @@
 from pyams_content.features.review.interfaces import IReviewTarget
 from pyams_content.shared.view.interfaces import IView, IWfView, IWfViewFactory, IViewQuery, \
     IViewQueryParamsExtension, IViewQueryFilterExtension, VIEW_CONTENT_TYPE, VIEW_CONTENT_NAME, IViewSettings
+from pyams_utils.interfaces import ICacheKeyValue
 from zope.intid.interfaces import IIntIds
 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
 
@@ -86,13 +87,12 @@
         return list(content_types)
 
     def get_results(self, context):
-        intids = get_utility(IIntIds)
         views_cache = get_cache(VIEWS_CACHE_REGION, VIEWS_CACHE_NAME)
         if self.is_using_context:
-            cache_key = VIEW_CONTEXT_CACHE_KEY.format(view=intids.queryId(self),
-                                                      context=intids.queryId(context))
+            cache_key = VIEW_CONTEXT_CACHE_KEY.format(view=ICacheKeyValue(self),
+                                                      context=ICacheKeyValue(context))
         else:
-            cache_key = VIEW_CACHE_KEY.format(view=intids.queryId(self))
+            cache_key = VIEW_CACHE_KEY.format(ICacheKeyValue(self))
         try:
             results = views_cache.get_value(cache_key)
         except KeyError:
@@ -101,6 +101,7 @@
             if adapter is None:
                 adapter = registry.getAdapter(self, IViewQuery)
             results = adapter.get_results(context, self.limit)
+            intids = get_utility(IIntIds)
             views_cache.set_value(cache_key, [intids.queryId(item) for item in results])
             logger.debug("Storing view items to cache key {0}".format(cache_key))
         else: