# HG changeset patch # User Thierry Florac # Date 1529591700 -7200 # Node ID 2f25e871eea1d22043d10ce048f18ff0d1784f92 # Parent d4b00aa0a9e063ed78a94bb8effa6df667cbdce2 Use ICacheKeyValue interface to get view's cache key diff -r d4b00aa0a9e0 -r 2f25e871eea1 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: