Final Class Yiisoft\Cache\Cache
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Cache provides support for the data caching, including cache key composition and dependencies, and uses
"Probably early expiration" for cache stampede prevention. The actual data caching is performed via
PSR-16 {@see \
You can use PSR-16 methods via {@see \
See also Yiisoft\
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getOrSet() | Yiisoft\ |
|
| psr() | Yiisoft\ |
|
| remove() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $handler | \ |
The actual cache handler. |
| $defaultTtl | DateInterval|integer|Yiisoft\ |
The default TTL for a cache entry.
null meaning infinity, negative or zero results in the cache key deletion.
This value is used by {@see \ |
public function __construct(\Psr\SimpleCache\CacheInterface $handler, Ttl|DateInterval|int|null $defaultTtl = null)
{
$this->psr = new DependencyAwareCache($this, $handler);
$this->items = new CacheItems();
$this->defaultTtl = Ttl::from($defaultTtl);
}
| public mixed getOrSet ( mixed $key, callable $callable, DateInterval|integer|null $ttl = null, ?\ | ||
| $key | mixed | |
| $callable | callable | |
| $ttl | DateInterval|integer|null | |
| $dependency | ?\ |
|
| $beta | float | |
public function getOrSet(
mixed $key,
callable $callable,
DateInterval|int|null $ttl = null,
?Dependency $dependency = null,
float $beta = 1.0,
) {
$ttlObj = Ttl::from($ttl ?? $this->defaultTtl);
$key = CacheKeyNormalizer::normalize($key);
$value = $this->getValue($key, $beta);
return $value ?? $this->setAndGet($key, $callable, $ttlObj, $dependency);
}
| public \ |
public function psr(): \Psr\SimpleCache\CacheInterface
{
return $this->psr;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.