0 follower

Final Class Yiisoft\Cache\Dependency\AnyDependency

InheritanceYiisoft\Cache\Dependency\AnyDependency » Yiisoft\Cache\Dependency\Dependency

AnyDependency represents a dependency which is composed of a list of other dependencies.

The dependency is reported as changed if any sub-dependency is changed.

Protected Properties

Hide inherited properties

Property Type Description Defined By
$data mixed The dependency data that is saved in cache and later is compared with the latest dependency data. Yiisoft\Cache\Dependency\Dependency
$isReusable boolean Whether this dependency is reusable or not. Yiisoft\Cache\Dependency\Dependency

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Cache\Dependency\AnyDependency
evaluateDependency() Yiisoft\Cache\Dependency\AnyDependency
isChanged() Yiisoft\Cache\Dependency\AnyDependency
markAsReusable() Changes dependency behavior so dependent data for this cache dependency will be generated only once per request. Yiisoft\Cache\Dependency\Dependency
resetReusableData() Resets all cached data for reusable dependencies. Yiisoft\Cache\Dependency\Dependency

Protected Methods

Hide inherited methods

Method Description Defined By
generateDependencyData() Yiisoft\Cache\Dependency\AnyDependency
generateReusableHash() Generates a unique hash that can be used for retrieving reusable dependency data. Yiisoft\Cache\Dependency\Dependency
iterableToArray() Converts iterable to array. Yiisoft\Cache\Dependency\Dependency

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Cache\Dependency\Dependency[] $dependencies = [] )
$dependencies Yiisoft\Cache\Dependency\Dependency[]

List of dependencies that this dependency is composed of. Each array element must be a dependency object.

                public function __construct(array $dependencies = [])
{
    foreach ($dependencies as $dependency) {
        if (!($dependency instanceof Dependency)) {
            throw new InvalidArgumentException(sprintf(
                'The dependency must be a "%s" instance, "%s" received',
                Dependency::class,
                get_debug_type($dependency),
            ));
        }
    }
    $this->dependencies = $dependencies;
}

            
evaluateDependency() public method

public void evaluateDependency ( Yiisoft\Cache\CacheInterface $cache )
$cache Yiisoft\Cache\CacheInterface

                public function evaluateDependency(CacheInterface $cache): void
{
    foreach ($this->dependencies as $dependency) {
        $dependency->evaluateDependency($cache);
    }
}

            
generateDependencyData() protected method

protected mixed generateDependencyData ( Yiisoft\Cache\CacheInterface $cache )
$cache Yiisoft\Cache\CacheInterface

                protected function generateDependencyData(CacheInterface $cache): mixed
{
    return null;
}

            
generateReusableHash() protected method

Defined in: Yiisoft\Cache\Dependency\Dependency::generateReusableHash()

Generates a unique hash that can be used for retrieving reusable dependency data.

See also \Yiisoft\Cache\Dependency\isReusable().

protected string generateReusableHash ( )
return string

A unique hash value for this cache dependency.

                protected function generateReusableHash(): string
{
    $data = $this->data;
    $this->data = null; // https://github.com/yiisoft/yii2/issues/3052
    $key = sha1(serialize($this));
    $this->data = $data;
    return $key;
}

            
isChanged() public method

public boolean isChanged ( Yiisoft\Cache\CacheInterface $cache )
$cache Yiisoft\Cache\CacheInterface

                public function isChanged(CacheInterface $cache): bool
{
    foreach ($this->dependencies as $dependency) {
        if ($dependency->isChanged($cache)) {
            return true;
        }
    }
    return false;
}

            
iterableToArray() protected method

Defined in: Yiisoft\Cache\Dependency\Dependency::iterableToArray()

Converts iterable to array.

protected array iterableToArray ( iterable $iterable )
$iterable iterable

                protected function iterableToArray(iterable $iterable): array
{
    /** @psalm-suppress RedundantCast */
    return $iterable instanceof Traversable ? iterator_to_array($iterable) : (array) $iterable;
}

            
markAsReusable() public method

Defined in: Yiisoft\Cache\Dependency\Dependency::markAsReusable()

Changes dependency behavior so dependent data for this cache dependency will be generated only once per request.

This allows you to use the same cache dependency for multiple separate cache calls while generating the same page without an overhead of re-evaluating dependency data each time.

public void markAsReusable ( )

                public function markAsReusable(): void
{
    $this->isReusable = true;
}

            
resetReusableData() public static method

Defined in: Yiisoft\Cache\Dependency\Dependency::resetReusableData()

Resets all cached data for reusable dependencies.

public static void resetReusableData ( )

                public static function resetReusableData(): void
{
    self::$reusableData = [];
}