protected function key(string $primary_key, $sub_key): string
    {
        if (!$this->enabled) {
            return ''; // Not possible.
            //
        } elseif (!($namespaced_primary_key = $this->nspKey($primary_key))) {
            return ''; // Not possible; e.g., empty key.
        }
        $namespaced_primary_key_uuid = ''; // Initialize.

        do { // Avoid race issues.
            $attempts = $attempts ?? 0;
            ++$attempts; // Counter.

            if (($existing_namespaced_primary_key_uuid = (string) $this->Pool->get($namespaced_primary_key))) {
                $namespaced_primary_key_uuid = $existing_namespaced_primary_key_uuid;
                break; // All good; stop here.
            }
            if (!isset($new_namespaced_primary_key_uuid)) {
                $new_namespaced_primary_key_uuid = $this->c::uuidV4();
            }
            if ($this->Pool->add($namespaced_primary_key, $new_namespaced_primary_key_uuid)) {
                $namespaced_primary_key_uuid = $new_namespaced_primary_key_uuid;
                break; // All good; stop here.
            }
            $result_code = $this->Pool->getResultCode();
            //
        } while ($attempts < $this::MAX_WRITE_ATTEMPTS && $result_code === \Memcached::RES_NOTSTORED);

        if (!$namespaced_primary_key_uuid) {
            return ''; // Failure; e.g., race condition.
        }
        $sub_key                            = (string) $sub_key;
        $namespaced_primary_key_uuid_prefix = $namespaced_primary_key_uuid.'\\';
        $namespaced_key                     = $namespaced_primary_key_uuid_prefix.$sub_key;

        if (isset($namespaced_key[251])) {
            throw $this->c::issue(sprintf('Sub key too long; %1$s bytes max.', 250 - strlen($namespaced_primary_key_uuid_prefix)));
        }
        return $namespaced_key;
    }
protected function key(string $primary_key, $sub_key): string
    {
        if (!$this->enabled) {
            return ''; // Not possible.
            //
        } elseif (!($namespaced_primary_key = $this->nspKey($primary_key))) {
            return ''; // Not possible; e.g., empty key.
        }
        $namespaced_primary_key_uuid = ''; // Initialize.

        do { // Avoid race issues.
            $attempts = $attempts ?? 0;
            ++$attempts; // Counter.

            if (($existing_namespaced_primary_key_uuid = (string) $this->Pool->get($namespaced_primary_key))) {
                $namespaced_primary_key_uuid = $existing_namespaced_primary_key_uuid;
                break; // All good; stop here.
            }
            if (!isset($new_namespaced_primary_key_uuid)) {
                $new_namespaced_primary_key_uuid = $this->c::uuidV4();
            }
            if ($this->Pool->add($namespaced_primary_key, $new_namespaced_primary_key_uuid)) {
                $namespaced_primary_key_uuid = $new_namespaced_primary_key_uuid;
                break; // All good; stop here.
            }
            $result_code = $this->Pool->getResultCode();
            //
        } while ($attempts < $this::MAX_WRITE_ATTEMPTS && $result_code === \Memcached::RES_NOTSTORED);

        if (!$namespaced_primary_key_uuid) {
            return ''; // Failure; e.g., race condition.
        }
        $sub_key                            = (string) $sub_key;
        $namespaced_primary_key_uuid_prefix = $namespaced_primary_key_uuid.'\\';
        $namespaced_key                     = $namespaced_primary_key_uuid_prefix.$sub_key;

        if (isset($namespaced_key[251])) {
            throw $this->c::issue(sprintf('Sub key too long; %1$s bytes max.', 250 - strlen($namespaced_primary_key_uuid_prefix)));
        }
        return $namespaced_key;
    }
protected function key ( string $ primary_key , $ sub_key ) : string { if ( ! $ this -> enabled ) { return '' ; // Not possible. // } elseif ( ! ( $ namespaced_primary_key = $ this -> nspKey ( $ primary_key ) ) ) { return '' ; // Not possible; e.g., empty key. } $ namespaced_primary_key_uuid = '' ; // Initialize. do { // Avoid race issues. $ attempts = $ attempts ?? 0 ; ++ $ attempts ; // Counter. if ( ( $ existing_namespaced_primary_key_uuid = ( string ) $ this -> Pool -> get ( $ namespaced_primary_key ) ) ) { $ namespaced_primary_key_uuid = $ existing_namespaced_primary_key_uuid ; break ; // All good; stop here. } if ( ! isset ( $ new_namespaced_primary_key_uuid ) ) { $ new_namespaced_primary_key_uuid = $ this -> c :: uuidV4 ( ) ; } if ( $ this -> Pool -> add ( $ namespaced_primary_key , $ new_namespaced_primary_key_uuid ) ) { $ namespaced_primary_key_uuid = $ new_namespaced_primary_key_uuid ; break ; // All good; stop here. } $ result_code = $ this -> Pool -> getResultCode ( ) ; // } while ( $ attempts < $ this :: MAX_WRITE_ATTEMPTS && $ result_code === \ Memcached :: RES_NOTSTORED ) ; if ( ! $ namespaced_primary_key_uuid ) { return '' ; // Failure; e.g., race condition. } $ sub_key = ( string ) $ sub_key ; $ namespaced_primary_key_uuid_prefix = $ namespaced_primary_key_uuid . '\\' ; $ namespaced_key = $ namespaced_primary_key_uuid_prefix . $ sub_key ; if ( isset ( $ namespaced_key [ 251 ] ) ) { throw $ this -> c :: issue ( sprintf ( 'Sub key too long; %1$s bytes max.' , 250 - strlen ( $ namespaced_primary_key_uuid_prefix ) ) ) ; } return $ namespaced_key ; }
Namespace a key.

@since 151216 Memcache utils.

@param string     $primary_key Primary key.
@param string|int $sub_key     Sub-key.

@return string Full namespaced cache key.
Namespace a key .