--- a/src/pyams_utils/cache.py Fri Jun 22 12:50:19 2018 +0200
+++ b/src/pyams_utils/cache.py Wed Jun 27 12:23:22 2018 +0200
@@ -18,9 +18,11 @@
# import interfaces
from persistent.interfaces import IPersistent
from pyams_utils.interfaces import ICacheKeyValue
+from pyams_utils.interfaces.tales import ITALESExtension
# import packages
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from zope.interface import Interface
@adapter_config(context=object, provides=ICacheKeyValue)
@@ -39,3 +41,16 @@
return str(int.from_bytes(obj._p_oid, byteorder='big'))
else: # unsaved object
return str(id(obj))
+
+
+@adapter_config(name='cache_key', context=(Interface, Interface, Interface), provides=ITALESExtension)
+class CacheKeyTalesExtension(ContextRequestViewAdapter):
+ """extension:cache_key(context) TALES extension
+
+ A PyAMS TALES extension which allows to render cache key value for a given context.
+ """
+
+ def render(self, context=None):
+ if context is None:
+ context = self.request.context
+ return ICacheKeyValue(context)