0 follower

Final Class Yiisoft\Cache\ArrayCache

InheritanceYiisoft\Cache\ArrayCache
ImplementsPsr\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.

Constants

Hide inherited constants

Constant Value Description Defined By
EXPIRATION_EXPIRED -1 Yiisoft\Cache\ArrayCache
EXPIRATION_INFINITY 0 Yiisoft\Cache\ArrayCache

Method Details

Hide inherited methods

clear() public method

public clear( ): boolean

                public function clear(): bool
{
    $this->cache = [];
    return true;
}

            
delete() public method

public delete( string $key ): boolean
$key string

                public function delete(string $key): bool
{
    $this->validateKey($key);
    unset($this->cache[$key]);
    return true;
}

            
deleteMultiple() public method

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;
}

            
get() public method

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;
}

            
getMultiple() public method

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;
}

            
has() public method

public has( string $key ): boolean
$key string

                public function has(string $key): bool
{
    $this->validateKey($key);
    return !$this->isExpired($key);
}

            
set() public method

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;
}

            
setMultiple() public method

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;
}