[Erp5-report] r28982 - /erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Sep 11 17:54:49 CEST 2009


Author: nicolas
Date: Fri Sep 11 17:54:47 2009
New Revision: 28982

URL: http://svn.erp5.org?rev=28982&view=rev
Log:
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)


Modified:
    erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py

Modified: erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py?rev=28982&r1=28981&r2=28982&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py [utf8] Fri Sep 11 17:54:47 2009
@@ -36,7 +36,7 @@
 from BaseCache import CacheEntry
 from Products.ERP5Type import interfaces
 import zope.interface
-import string
+from binascii import b2a_hex
 
 try:
   import memcache
@@ -109,11 +109,10 @@
     ## such behaviour when constructing cache_id we add scope in front
     cache_id = "%s%s%s%s" % (self._key_prefix, self._cache_plugin_path,
                              scope, cache_id)
-    #Some chars are not allowed by memcached to build the key
-    cache_id = cache_id.translate(string.maketrans('', ''), '[]()<>\'", ')
-    if self._server_max_key_length != 0:
-      ## memcached will fail to store cache_id longer than MEMCACHED_SERVER_MAX_KEY_LENGTH.
-      return cache_id[:self._server_max_key_length]
+    # Escape key to normalise some chars
+    # which are not allowed by memcached
+    # Could reach the limit of max_key_len
+    cache_id = b2a_hex(cache_id)
     return cache_id
 
   def get(self, cache_id, scope, default=_MARKER):




More information about the Erp5-report mailing list