dougtabuchi avatar dougtabuchi committed 1b9374f

Hashing keys + test.

Comments (0)

Files changed (2)

 import beaker.ext.sqla as sqla
 import as google
+import uuid
 # Initialize the cache region dict
 cache_regions = {}
 """Dictionary of 'region' arguments.
     def __init__(self, namespace, type='memory', expiretime=None,
-                 starttime=None, expire=None, **nsargs):
+                 starttime=None, expire=None, hash_keys = False,
+                 **nsargs):
             cls = clsmap[type]
             if isinstance(cls, InvalidCacheBackendError):
         self.namespace = cls(namespace, **nsargs)
         self.expiretime = expiretime or expire
         self.starttime = starttime
+        self.hash_keys = hash_keys
         self.nsargs = nsargs
         if isinstance(key, unicode):
             key = key.encode('ascii', 'backslashreplace')
+        if self.hash_keys:
+            key = str(uuid.uuid5(uuid.NAMESPACE_DNS,key))
         if 'type' in kw:
             return self._legacy_get_value(key, **kw)
         kw.setdefault('expiretime', self.expiretime)
         kw.setdefault('starttime', self.starttime)
         return container.Value(key, self.namespace, **kw)
     @util.deprecated("Specifying a "
     cache_key = " ".join(map(str, args))


         assert "foo" not in cache
         assert not cache.has_key("test")
+def test_key_too_long():
+    MAX_KEY_SIZE = 600
+    cache = Cache('', data_dir='./cache', url=mc_url, type='ext:memcached',
+                  hash_keys=True)
+    cache.set_value(BIG_KEY, 24)
+    assert cache.has_key(BIG_KEY)
+    assert cache.get(BIG_KEY)==24
+    assert cache[BIG_KEY]==24
+    assert BIG_KEY in cache
+    cache.remove_value(BIG_KEY)
+    assert not cache.has_key(BIG_KEY)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.