Commit a0eefb13 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* use Quoted Printable encode instead of 'removing invalid characters' to...

* use Quoted Printable encode instead of 'removing invalid characters' to encode keys for memcached.
* add a global prefix that makes it possible to share the same memcached with different ERP5 instances.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29531 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7bb3eda8
...@@ -32,6 +32,7 @@ from Products.ERP5Type.Tool.BaseTool import BaseTool ...@@ -32,6 +32,7 @@ from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions, _dtmldir from Products.ERP5Type import Permissions, _dtmldir
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import DTMLFile from Globals import DTMLFile
from quopri import encodestring
MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID = '_v_memcached_edited' MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID = '_v_memcached_edited'
...@@ -42,14 +43,12 @@ except ImportError: ...@@ -42,14 +43,12 @@ except ImportError:
def encodeKey(key): def encodeKey(key):
""" """
Encode the key. The current encoding is not very good Encode the key like 'Quoted Printable'.
since it is not bijective. Implementing a bijective
encoding is required.
""" """
# Memcached refuses characters which are below ' ' (included) in # According to the memcached's protocol.txt, the key cannot contain
# ascii table. Just strip them here to avoid the raise. # control characters and white spaces.
return ''.join([x for x in key if ord(x) > \ return encodestring(key, True).replace('\n', '').replace('\r', '')
MEMCACHED_MINIMUM_KEY_CHAR_ORD])
memcached_dict_pool = local() memcached_dict_pool = local()
if memcache is not None: if memcache is not None:
# Real memcache tool # Real memcache tool
...@@ -299,6 +298,9 @@ if memcache is not None: ...@@ -299,6 +298,9 @@ if memcache is not None:
plugin_path plugin_path
relative_url of dedicated Memcached Plugin relative_url of dedicated Memcached Plugin
""" """
global_prefix = getattr(self, 'erp5_site_global_id', '')
if global_prefix:
key_prefix = '%s_%s' % (global_prefix, key_prefix)
return SharedDict(self._getMemcachedDict(plugin_path), prefix=key_prefix) return SharedDict(self._getMemcachedDict(plugin_path), prefix=key_prefix)
else: else:
......
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