Final Class Yiisoft\View\Cache\CachedContent
| Inheritance | Yiisoft\ |
|---|
CacheContent caches content, supports the use of dynamic content {@see DynamicContent} inside cached content.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| cache() | Caches, replaces placeholders with actual dynamic content, and returns the full actual content. | Yiisoft\ |
| get() | Returns cached content with placeholders replaced with actual dynamic content. | Yiisoft\ |
Method Details
| public mixed __construct ( string $id, \ | ||
| $id | string |
The unique identifier of the cached content. |
| $cache | \ |
The cache instance. |
| $dynamicContents | Yiisoft\ |
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->setDynamicContents($dynamicContents);
$this->setVariations($variations);
}
Caches, replaces placeholders with actual dynamic content, and returns the full actual content.
See also \
| public string cache ( string $content, DateInterval|integer|null $ttl = 60, \ | ||
| $content | string |
The content of the item to cache store. |
| $ttl | DateInterval|integer|null |
The TTL of the cached content. |
| $dependency | \ |
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 $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);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.