protected function makeKeyString($key, $path = false) { // array(name, sub); // a => name, b => sub; $key = ehough_stash_Utilities::normalizeKeys($key); $keyString = 'cache:::'; foreach ($key as $name) { //a. cache:::name //b. cache:::name0:::sub $keyString .= $name; //a. :pathdb::cache:::name //b. :pathdb::cache:::name0:::sub $pathKey = ':pathdb::' . $keyString; $pathKey = md5($pathKey); if (isset($this->keyCache[$pathKey])) { $index = $this->keyCache[$pathKey]; } else { $index = $this->memcache->cas($pathKey, 0); $this->keyCache[$pathKey] = $index; } //a. cache:::name0::: //b. cache:::name0:::sub1::: $keyString .= '_' . $index . ':::'; } return $path ? $pathKey : md5($keyString); }
/** * Turns a key array into a key string. This includes running the indexing functions used to manage the memcached * hierarchical storage. * * When requested the actual path, rather than a normalized value, is returned. * * @param array $key * @param bool $path * @return string */ protected function makeKeyString($key, $path = false) { $key = ehough_stash_Utilities::normalizeKeys($key); $keyString = ':cache:::'; $pathKey = ':pathdb::'; $time = microtime(true); if ($time - $this->keyCacheTime >= $this->keyCacheTimeLimit) { $this->keyCacheTime = $time; $this->keyCache = array(); } foreach ($key as $name) { //a. cache:::name //b. cache:::name0:::sub $keyString .= $name; //a. :pathdb::cache:::name //b. :pathdb::cache:::name0:::sub $pathKey = ':pathdb::' . $keyString; $pathKey = md5($pathKey); if (isset($this->keyCache[$pathKey])) { $index = $this->keyCache[$pathKey]; } else { $index = $this->memcache->cas($pathKey, 0); $this->keyCache[$pathKey] = $index; } //a. cache:::name0::: //b. cache:::name0:::sub1::: $keyString .= '_' . $index . ':::'; } return $path ? $pathKey : md5($keyString); }