Commit cd7f137f authored by Jeremy's avatar Jeremy

Bug #525400: hash keys if longer than 250 bytes, as otherwise they get

truncated by memcache leading to collisions.
parent 4e372aad
......@@ -305,9 +305,18 @@ function dmemcache_key($key, $bin = 'cache') {
// memcache_key_prefix can be set in settings.php to support site namespaces
// in a multisite environment.
if (empty($prefix)) {
$prefix = variable_get('memcache_key_prefix', '');
if ($prefix = variable_get('memcache_key_prefix', '')) {
$prefix .= '-';
}
}
$full_key = urlencode($prefix . $bin . '-' . $key);
// Memcache only supports key lengths up to 250 bytes. If we have generated
// a longer key, hash it with sha1 which will shrink the key down to 40 bytes
// while still keeping it unique.
if (strlen($full_key) > 250) {
$full_key = $prefix . $bin . '-' . sha1($key);
}
$full_key = ($prefix ? $prefix. '-' : '') . $bin . '-' . $key;
return urlencode($full_key);
return $full_key;
}
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