Commit 9c645489 authored by Nicolas Delaby's avatar Nicolas Delaby

Avoid key stripping and key cutting to avoid collision between keys provided by user.

 *Let Memcached Plugin deal with SERVER_MAX_KEY_LEN
 *escape key with hexadecimal encoder which output allowed chars (binascii.b2a_hex)



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28982 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 40b74a22
...@@ -36,7 +36,7 @@ from BaseCache import BaseCache ...@@ -36,7 +36,7 @@ from BaseCache import BaseCache
from BaseCache import CacheEntry from BaseCache import CacheEntry
from Products.ERP5Type import interfaces from Products.ERP5Type import interfaces
import zope.interface import zope.interface
import string from binascii import b2a_hex
try: try:
import memcache import memcache
...@@ -109,11 +109,10 @@ class DistributedRamCache(BaseCache): ...@@ -109,11 +109,10 @@ class DistributedRamCache(BaseCache):
## such behaviour when constructing cache_id we add scope in front ## such behaviour when constructing cache_id we add scope in front
cache_id = "%s%s%s%s" % (self._key_prefix, self._cache_plugin_path, cache_id = "%s%s%s%s" % (self._key_prefix, self._cache_plugin_path,
scope, cache_id) scope, cache_id)
#Some chars are not allowed by memcached to build the key # Escape key to normalise some chars
cache_id = cache_id.translate(string.maketrans('', ''), '[]()<>\'", ') # which are not allowed by memcached
if self._server_max_key_length != 0: # Could reach the limit of max_key_len
## memcached will fail to store cache_id longer than MEMCACHED_SERVER_MAX_KEY_LENGTH. cache_id = b2a_hex(cache_id)
return cache_id[:self._server_max_key_length]
return cache_id return cache_id
def get(self, cache_id, scope, default=_MARKER): def get(self, cache_id, scope, default=_MARKER):
......
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