Cache\Hierarchy\HierarchicalCachePoolTrait::getHierarchyKey PHP Method

getHierarchyKey() protected method

Get a key to use with the hierarchy. If the key does not start with HierarchicalPoolInterface::SEPARATOR this will return an unalterered key. This function supports a tagged key. Ie "foo:bar".
protected getHierarchyKey ( string $key, &$pathKey = null ) : string
$key string The original key
return string
    protected function getHierarchyKey($key, &$pathKey = null)
    {
        if (!$this->isHierarchyKey($key)) {
            return $key;
        }
        $key = $this->explodeKey($key);
        $keyString = '';
        // The comments below is for a $key = ["foo!tagHash", "bar!tagHash"]
        foreach ($key as $name) {
            // 1) $keyString = "foo!tagHash"
            // 2) $keyString = "foo!tagHash![foo_index]!bar!tagHash"
            $keyString .= $name;
            $pathKey = sha1('path' . TaggablePoolInterface::TAG_SEPARATOR . $keyString);
            if (isset($this->keyCache[$pathKey])) {
                $index = $this->keyCache[$pathKey];
            } else {
                $index = $this->getValueFormStore($pathKey);
                $this->keyCache[$pathKey] = $index;
            }
            // 1) $keyString = "foo!tagHash![foo_index]!"
            // 2) $keyString = "foo!tagHash![foo_index]!bar!tagHash![bar_index]!"
            $keyString .= TaggablePoolInterface::TAG_SEPARATOR . $index . TaggablePoolInterface::TAG_SEPARATOR;
        }
        // Assert: $pathKey = "path!foo!tagHash![foo_index]!bar!tagHash"
        // Assert: $keyString = "foo!tagHash![foo_index]!bar!tagHash![bar_index]!"
        // Make sure we do not get awfully long (>250 chars) keys
        return sha1($keyString);
    }