src/GetCachedCapableTrait.php
protected function _getCached($key, $default = null, $ttl = null)
    {
        try {
            return $this->_get($key);
        } catch (NotFoundExceptionInterface $e) {
            if (is_callable($default)) {
                try {
                    $args    = $this->_normalizeArray($this->_getGeneratorArgs($key, $default, $ttl));
                    $default = $this->_invokeCallable($default, $args);
                } catch (RootException $e) {
                    throw $this->_createRuntimeException($this->__('Could not generate value'), null, $e);
                }
            }

            $this->_set($key, $default, $ttl);

            return $default;
        }
    }
protected function _getCached($key, $default = null, $ttl = null)
    {
        try {
            return $this->_get($key);
        } catch (NotFoundExceptionInterface $e) {
            if (is_callable($default)) {
                try {
                    $args    = $this->_normalizeArray($this->_getGeneratorArgs($key, $default, $ttl));
                    $default = $this->_invokeCallable($default, $args);
                } catch (RootException $e) {
                    throw $this->_createRuntimeException($this->__('Could not generate value'), null, $e);
                }
            }

            $this->_set($key, $default, $ttl);

            return $default;
        }
    }
protected function _getCached ( $ key , $ default = null , $ ttl = null ) { try { return $ this -> _get ( $ key ) ; } catch ( NotFoundExceptionInterface $ e ) { if ( is_callable ( $ default ) ) { try { $ args = $ this -> _normalizeArray ( $ this -> _getGeneratorArgs ( $ key , $ default , $ ttl ) ) ; $ default = $ this -> _invokeCallable ( $ default , $ args ) ; } catch ( RootException $ e ) { throw $ this -> _createRuntimeException ( $ this -> __ ( 'Could not generate value' ) , null , $ e ) ; } } $ this -> _set ( $ key , $ default , $ ttl ) ; return $ default ; } }
Retrieves a cached value by key, generating it if it does not exist.

This implementation does not support TTL. Values will remain valid for the lifetime of this
instance, or until removed.

@since [*next-version*]

@param string|int|float|bool|Stringable $key     The key to retrieve the value for.
@param null|callable|mixed              $default The value to return if key isn't found. If this is a callable,
it will be invoked and the result will be used as default.
@param null|null|int|string|string      $ttl     The number of seconds for the value to be considered valid.
If null, the behaviour is undefined, and the value may live indefinitely.

@throws InvalidArgumentException    If creator is not a callable, or TTL is invalid.
@throws OutOfRangeException         If the key is invalid.
@throws ContainerExceptionInterface If problem reading or writing the value.
@throws RuntimeException            If value could not be generated.

@return mixed The cached value.
Retrieves a cached value by key generating it if it does not exist .