diff --git a/product/ERP5Type/Cache.py b/product/ERP5Type/Cache.py index 21827d8a5cb98f8e1864baf5dc549e4d1f1870de..5198c5f44c779fb010b3c6a0c6f90f4cadc80f8a 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