Final Class Yiisoft\Cache\ArrayCache
| Inheritance | Yiisoft\Cache\ArrayCache |
|---|---|
| Implements | Psr\SimpleCache\CacheInterface |
ArrayCache provides caching for the current request only by storing the values in an array.
See \Psr\SimpleCache\CacheInterface for common cache operations that ArrayCache supports.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| EXPIRATION_EXPIRED | -1 | Yiisoft\Cache\ArrayCache | |
| EXPIRATION_INFINITY | 0 | Yiisoft\Cache\ArrayCache |
Method Details
| public delete( string $key ): boolean | ||
| $key | string | |
public function delete(string $key): bool
{
$this->validateKey($key);
unset($this->cache[$key]);
return true;
}
| public deleteMultiple( iterable $keys ): boolean | ||
| $keys | iterable | |
public function deleteMultiple(iterable $keys): bool
{
$keys = $this->iterableToArray($keys);
/** @psalm-suppress RedundantCondition */
$this->validateKeys($keys);
foreach ($keys as $key) {
$this->delete($key);
}
return true;
}
| public get( string $key, mixed $default = null ): mixed | ||
| $key | string | |
| $default | mixed | |
public function get(string $key, mixed $default = null): mixed
{
if ($this->has($key)) {
$value = $this->cache[$key][0];
if (is_object($value)) {
return clone $value;
}
return $value;
}
return $default;
}
| public getMultiple( iterable $keys, mixed $default = null ): iterable | ||
| $keys | iterable | |
| $default | mixed | |
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$keys = $this->iterableToArray($keys);
/** @psalm-suppress RedundantCondition */
$this->validateKeys($keys);
$results = [];
foreach ($keys as $key) {
$value = $this->get($key, $default);
$results[$key] = $value;
}
return $results;
}
| public has( string $key ): boolean | ||
| $key | string | |
public function has(string $key): bool
{
$this->validateKey($key);
return !$this->isExpired($key);
}
| public set( string $key, mixed $value, integer|DateInterval|null $ttl = null ): boolean | ||
| $key | string | |
| $value | mixed | |
| $ttl | integer|DateInterval|null | |
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$this->validateKey($key);
$expiration = $this->ttlToExpiration(Ttl::from($ttl));
if ($expiration < 0) {
return $this->delete($key);
}
if (is_object($value)) {
$value = clone $value;
}
$this->cache[$key] = [$value, $expiration];
return true;
}
| public setMultiple( iterable $values, integer|DateInterval|null $ttl = null ): boolean | ||
| $values | iterable | |
| $ttl | integer|DateInterval|null | |
public function setMultiple(iterable $values, int|DateInterval|null $ttl = null): bool
{
$values = $this->iterableToArray($values);
$this->validateKeysOfValues($values);
foreach ($values as $key => $value) {
$this->set((string) $key, $value, $ttl);
}
return true;
}
Signup or Login in order to comment.