Commit e83b3536 authored by Jérome Perrin's avatar Jérome Perrin

According to memcached protocol, if expiration is greater than 30 days, it is

not expressed in seconds but as a timestamp. Expirations in ERP5 are always
expressed in seconds, so we have to treat differently expiration greater than
30 days.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40409 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 73f0af13
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
# #
############################################################################## ##############################################################################
import time
from threading import local from threading import local
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions, _dtmldir from Products.ERP5Type import Permissions, _dtmldir
...@@ -95,6 +96,8 @@ if memcache is not None: ...@@ -95,6 +96,8 @@ if memcache is not None:
self.local_cache = {} self.local_cache = {}
self.scheduled_action_dict = {} self.scheduled_action_dict = {}
self.server_list = server_list self.server_list = server_list
# see "Expiration times" from memcached protocol docs
self.expiration_time_since_epoch = expiration_time > (60*60*24*30)
self.expiration_time = expiration_time self.expiration_time = expiration_time
self.server_max_key_length = server_max_key_length self.server_max_key_length = server_max_key_length
self.server_max_value_length = server_max_value_length self.server_max_value_length = server_max_value_length
...@@ -126,6 +129,9 @@ if memcache is not None: ...@@ -126,6 +129,9 @@ if memcache is not None:
would not be ignored. would not be ignored.
""" """
try: try:
expiration_time = self.expiration_time
if self.expiration_time_since_epoch:
expiration_time += time.time()
for key, value in self.local_cache.iteritems(): for key, value in self.local_cache.iteritems():
if getattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, None): if getattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, None):
delattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID) delattr(value, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID)
...@@ -133,13 +139,13 @@ if memcache is not None: ...@@ -133,13 +139,13 @@ if memcache is not None:
for key, action in self.scheduled_action_dict.iteritems(): for key, action in self.scheduled_action_dict.iteritems():
if action is UPDATE_ACTION: if action is UPDATE_ACTION:
succeed = self.memcached_connection.set(encodeKey(key), succeed = self.memcached_connection.set(encodeKey(key),
self.local_cache[key], self.local_cache[key],
self.expiration_time) expiration_time)
if not succeed: if not succeed:
self._initialiseConnection() self._initialiseConnection()
succeed = self.memcached_connection.set(encodeKey(key), succeed = self.memcached_connection.set(encodeKey(key),
self.local_cache[key], self.local_cache[key],
self.expiration_time) expiration_time)
if not succeed: if not succeed:
LOG('MemcacheTool', 0, 'set command to memcached server (%r) failed' % (self.server_list,)) LOG('MemcacheTool', 0, 'set command to memcached server (%r) failed' % (self.server_list,))
elif action is DELETE_ACTION: elif action is DELETE_ACTION:
......
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