Final Class Yiisoft\View\Cache\CachedContent
| Inheritance | Yiisoft\View\Cache\CachedContent |
|---|
CacheContent caches content, supports the use of dynamic content {@see DynamicContent} inside cached content.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\View\Cache\CachedContent | |
| cache() | Caches, replaces placeholders with actual dynamic content, and returns the full actual content. | Yiisoft\View\Cache\CachedContent |
| get() | Returns cached content with placeholders replaced with actual dynamic content. | Yiisoft\View\Cache\CachedContent |
Method Details
| public mixed __construct ( string $id, \Yiisoft\Cache\CacheInterface $cache, Yiisoft\View\Cache\DynamicContent[] $dynamicContents = [], string[] $variations = [] ) | ||
| $id | string |
The unique identifier of the cached content. |
| $cache | \Yiisoft\Cache\CacheInterface |
The cache instance. |
| $dynamicContents | Yiisoft\View\Cache\DynamicContent[] |
The dynamic content instances. |
| $variations | string[] |
List of string factors that would cause the variation of the content being cached. |
public function __construct(
private readonly string $id,
private readonly CacheInterface $cache,
array $dynamicContents = [],
array $variations = []
) {
$this->cacheKeyNormalizer = new CacheKeyNormalizer();
$this->setDynamicContents($dynamicContents);
$this->setVariations($variations);
}
Caches, replaces placeholders with actual dynamic content, and returns the full actual content.
See also \Yiisoft\Cache\CacheInterface::getOrSet().
| public string cache ( string $content, DateInterval|integer|null $ttl = 60, \Yiisoft\Cache\Dependency\Dependency|null $dependency = null, float $beta = 1.0 ) | ||
| $content | string |
The content of the item to cache store. |
| $ttl | DateInterval|integer|null |
The TTL of the cached content. |
| $dependency | \Yiisoft\Cache\Dependency\Dependency|null |
The dependency of the cached content. |
| $beta | float |
The value for calculating the range that is used for "Probably early expiration". |
| return | string |
The rendered cached content. |
|---|---|---|
public function cache(
string $content,
DateInterval|int|null $ttl = 60,
Dependency|null $dependency = null,
float $beta = 1.0
): string {
/** @psalm-suppress MixedArgument */
return $this->replaceDynamicPlaceholders(
$this->cache->getOrSet($this->cacheKey(), static fn(): string => $content, $ttl, $dependency, $beta),
);
}
Returns cached content with placeholders replaced with actual dynamic content.
| public string|null get ( ) | ||
| return | string|null |
The cached content. Null is returned if valid content is not found in the cache. |
|---|---|---|
public function get(): ?string
{
/** @var string|null $content */
$content = $this->cache
->psr()
->get($this->cacheKey());
if ($content === null) {
return null;
}
return $this->replaceDynamicPlaceholders($content);
}
Signup or Login in order to comment.