Final Class Yiisoft\Cache\Dependency\AllDependencies
| Inheritance | Yiisoft\Cache\Dependency\AllDependencies » Yiisoft\Cache\Dependency\Dependency |
|---|
AllDependencies represents a dependency which is composed of a list of other dependencies.
The dependency is reported as changed if all sub-dependencies are changed.
Protected 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
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Cache\Dependency\AllDependencies | |
| evaluateDependency() | Yiisoft\Cache\Dependency\AllDependencies | |
| isChanged() | Yiisoft\Cache\Dependency\AllDependencies | |
| 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
| Method | Description | Defined By |
|---|---|---|
| generateDependencyData() | Yiisoft\Cache\Dependency\AllDependencies | |
| 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
| 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;
}
| 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);
}
}
| protected mixed generateDependencyData ( Yiisoft\Cache\CacheInterface $cache ) | ||
| $cache | Yiisoft\Cache\CacheInterface | |
protected function generateDependencyData(CacheInterface $cache): mixed
{
return null;
}
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;
}
| 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 false;
}
}
return true;
}
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;
}
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;
}
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 = [];
}
Signup or Login in order to comment.