Final Class Yiisoft\Cache\Cache
| Inheritance | Yiisoft\Cache\Cache |
|---|---|
| Implements | Yiisoft\Cache\CacheInterface |
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 \Psr\SimpleCache\CacheInterface} instance passed to constructor.
You can use PSR-16 methods via {@see \Yiisoft\Cache\Cache::psr()}.
See also Yiisoft\Cache\CacheInterface.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Cache\Cache | |
| getOrSet() | Yiisoft\Cache\Cache | |
| psr() | Yiisoft\Cache\Cache | |
| remove() | Yiisoft\Cache\Cache |
Method Details
| public mixed __construct ( \Psr\SimpleCache\CacheInterface $handler, DateInterval|integer|Yiisoft\Cache\Ttl|null $defaultTtl = null ) | ||
| $handler | \Psr\SimpleCache\CacheInterface |
The actual cache handler. |
| $defaultTtl | DateInterval|integer|Yiisoft\Cache\Ttl|null |
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 \Yiisoft\Cache\getOrSet()}, if the duration is not explicitly given. |
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, Yiisoft\Cache\Dependency\Dependency|null $dependency = null, float $beta = 1.0 ) | ||
| $key | mixed | |
| $callable | callable | |
| $ttl | DateInterval|integer|null | |
| $dependency | Yiisoft\Cache\Dependency\Dependency|null | |
| $beta | float | |
public function getOrSet(
mixed $key,
callable $callable,
DateInterval|int|null $ttl = null,
Dependency|null $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 \Psr\SimpleCache\CacheInterface psr ( ) |
public function psr(): \Psr\SimpleCache\CacheInterface
{
return $this->psr;
}
Signup or Login in order to comment.