Final Class Yiisoft\Test\Support\SimpleCache\MemorySimpleCache
| Inheritance | Yiisoft\Test\Support\SimpleCache\MemorySimpleCache |
|---|---|
| Implements | Psr\SimpleCache\CacheInterface |
Public Properties
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $cache | array<string, array<integer, mixed>> | Yiisoft\Test\Support\SimpleCache\MemorySimpleCache |
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| EXPIRATION_EXPIRED | -1 | Yiisoft\Test\Support\SimpleCache\MemorySimpleCache | |
| EXPIRATION_INFINITY | 0 | Yiisoft\Test\Support\SimpleCache\MemorySimpleCache |
Property Details
Method Details
| public mixed __construct ( array $cacheData = [] ) | ||
| $cacheData | array | |
public function __construct(array $cacheData = [])
{
$this->setMultiple($cacheData);
}
| public boolean clear ( ) |
public function clear(): bool
{
$this->cache = [];
return $this->returnOnClear;
}
| public boolean delete ( string $key ) | ||
| $key | string | |
public function delete(string $key): bool
{
$this->validateKey($key);
unset($this->cache[$key]);
return $this->returnOnDelete;
}
| public boolean deleteMultiple ( iterable $keys ) | ||
| $keys | iterable | |
public function deleteMultiple(iterable $keys): bool
{
$keys = $this->iterableToArray($keys);
$this->validateKeys($keys);
/** @var string[] $keys */
foreach ($keys as $key) {
$this->delete($key);
}
return $this->returnOnDelete;
}
| public mixed get ( string $key, mixed $default = null ) | ||
| $key | string | |
| $default | mixed | |
public function get(string $key, mixed $default = null): mixed
{
$this->validateKey($key);
if (array_key_exists($key, $this->cache) && !$this->isExpired($key)) {
$value = $this->cache[$key][0];
if (is_object($value)) {
$value = clone $value;
}
return $value;
}
return $default;
}
| public iterable getMultiple ( iterable $keys, mixed $default = null ) | ||
| $keys | iterable | |
| $default | mixed | |
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$keys = $this->iterableToArray($keys);
$this->validateKeys($keys);
/** @psalm-var string[] $keys */
$result = [];
foreach ($keys as $key) {
$result[$key] = $this->get($key, $default);
}
return $result;
}
Get stored data
| public array<array-key, mixed> getValues ( ) |
public function getValues(): array
{
$result = [];
foreach ($this->cache as $key => $value) {
$result[$key] = $value[0];
}
return $result;
}
| public boolean has ( string $key ) | ||
| $key | string | |
public function has(string $key): bool
{
$this->validateKey($key);
/** @psalm-var string $key */
return isset($this->cache[$key]) && !$this->isExpired($key);
}
| public boolean set ( string $key, mixed $value, null|integer|DateInterval $ttl = null ) | ||
| $key | string | |
| $value | mixed | |
| $ttl | null|integer|DateInterval | |
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
{
$this->validateKey($key);
$expiration = $this->ttlToExpiration($ttl);
if ($expiration < 0) {
return $this->delete($key);
}
if (is_object($value)) {
$value = clone $value;
}
$this->cache[$key] = [$value, $expiration];
return $this->returnOnSet;
}
| public boolean setMultiple ( iterable $values, null|integer|DateInterval $ttl = null ) | ||
| $values | iterable | |
| $ttl | null|integer|DateInterval | |
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
{
$values = $this->iterableToArray($values);
$this->validateKeysOfValues($values);
foreach ($values as $key => $value) {
$this->set((string) $key, $value, $ttl);
}
return $this->returnOnSet;
}
Signup or Login in order to comment.