From 0a77ad939adfd00fd30735f1507d565c3b4fe777 Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Tue, 13 Dec 2005 13:36:43 +0000
Subject: [PATCH] Add some utility methods for a cache per transaction. This
 cache is only for a read-only transaction.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4626 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Cache.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/product/ERP5Type/Cache.py b/product/ERP5Type/Cache.py
index 21827d8a5c..5198c5f44c 100755
--- a/product/ERP5Type/Cache.py
+++ b/product/ERP5Type/Cache.py
@@ -142,3 +142,31 @@ allow_class(CachingMethod)
 
 def clearCache():
   CachingMethod.cached_object_dict.clear()
+
+# TransactionCache is a cache per transaction. The purpose of this cache is
+# to accelerate some heavy read-only operations. Note that this must not be
+# enabled when a trasaction may modify ZODB objects.
+def getTransactionCache(context):
+  """Get the transaction cache.
+  """
+  try:
+    return context.REQUEST._erp5_transaction_cache
+  except AttributeError:
+    return None
+    
+def enableTransactionCache(context):
+  """Enable the transaction cache.
+  """
+  try:
+    context.REQUEST._erp5_transaction_cache = {}
+  except AttributeError:
+    pass
+  
+def disableTransactionCache(context):
+  """Disable the transaction cache.
+  """
+  try:
+    del context.REQUEST._erp5_transaction_cache
+  except AttributeError:
+    pass
+    
\ No newline at end of file
-- 
2.30.9