Updated default cache key adapters
authorThierry Florac <thierry.florac@onf.fr>
Tue, 10 Apr 2018 14:44:20 +0200
changeset 165 f124b8ffaa50
parent 164 07d7bca9e2af
child 166 b4d5a6a883c0
Updated default cache key adapters
src/pyams_utils/cache.py
src/pyams_utils/zodb.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_utils/cache.py	Tue Apr 10 14:44:20 2018 +0200
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from persistent.interfaces import IPersistent
+from pyams_utils.interfaces import ICacheKeyValue
+
+# import packages
+from pyams_utils.adapter import adapter_config
+
+
+@adapter_config(context=object, provides=ICacheKeyValue)
+def object_cache_key_adapter(obj):
+    return str(id(obj))
+
+
+@adapter_config(context=str, provides=ICacheKeyValue)
+def string_cache_key_adapter(obj):
+    return obj
+
+
+@adapter_config(context=IPersistent, provides=ICacheKeyValue)
+def persistent_cache_key_adapter(obj):
+    return str(int.from_bytes(obj._p_oid, byteorder='big'))
--- a/src/pyams_utils/zodb.py	Thu Apr 05 15:32:14 2018 +0200
+++ b/src/pyams_utils/zodb.py	Tue Apr 10 14:44:20 2018 +0200
@@ -17,7 +17,6 @@
 
 # import interfaces
 from persistent.interfaces import IPersistent
-from pyams_utils.interfaces import ICacheKeyValue
 from pyams_utils.interfaces.site import IOptionalUtility
 from pyams_utils.interfaces.zeo import IZEOConnection
 from transaction.interfaces import ITransactionManager
@@ -71,16 +70,6 @@
         # recent spelling.
 
 
-@adapter_config(context=object, provides=ICacheKeyValue)
-def object_key_adapter(obj):
-    return str(id(obj))
-
-
-@adapter_config(context=str, provides=ICacheKeyValue)
-def string_key_adapter(obj):
-    return obj
-
-
 #
 # ZEO connection management
 #