Commit b92e5551 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use the API of Request correctly.

Check the expiration of cached objects only at the first time in each request.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6127 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 624f4af6
......@@ -96,7 +96,14 @@ class CachingMethod:
"""
global cache_check_time
# Store the current time in the REQUEST object, and
# check the expiration only at the first time.
from Products.ERP5Type.Utils import get_request
request = get_request()
now = request.get('_erp5_cache_time', None)
if now is None:
now = time()
request.set('_erp5_cache_time', now)
if cache_check_time + CACHE_CHECK_TIMEOUT < now:
# If the time reachs the timeout, expire all old entries.
......@@ -150,23 +157,16 @@ def getTransactionCache(context):
"""Get the transaction cache.
"""
try:
return context.REQUEST._erp5_transaction_cache
except AttributeError:
return context.REQUEST['_erp5_transaction_cache']
except KeyError:
return None
def enableTransactionCache(context):
"""Enable the transaction cache.
"""
try:
context.REQUEST._erp5_transaction_cache = {}
except AttributeError:
pass
context.REQUEST.set('_erp5_transaction_cache', {})
def disableTransactionCache(context):
"""Disable the transaction cache.
"""
try:
del context.REQUEST._erp5_transaction_cache
except AttributeError:
pass
\ No newline at end of file
context.REQUEST.set('_erp5_transaction_cache', None)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment