Documentation

AtomicCache
in package
uses ForbidCloning, ForbidSerialization

FinalYes
Tags
template

Table of Contents

Properties

$cache  : Cache
$mutex  : KeyedMutex

Methods

__construct()  : mixed
__serialize()  : never
__unserialize()  : never
compute()  : TValue
Obtains the lock for the given key, then invokes the {@code $compute} callback with the current cached value (which may be {@code null} if the key did not exist in the cache). The value returned from the callback is stored in the cache and returned from this method.
computeIfAbsent()  : TValue
Attempts to get the value for the given key. If the key is not found, the key is locked, the $compute callback is invoked with the key as the first parameter. The value returned from the callback is stored in the cache and returned from this method.
computeIfPresent()  : TValue
Attempts to get the value for the given key. If the key exists, the key is locked, the $compute callback is invoked with the key as the first parameter and the current key value as the second parameter. The value returned from the callback is stored in the cache and returned from this method.
delete()  : bool|null
The lock is obtained for the key before deleting the key.
get()  : TValue|TDefault
Returns the cached value for the key or the given default value if the key does not exist.
set()  : void
The lock is obtained for the key before setting the value.
__clone()  : mixed
create()  : mixed
lock()  : Lock

Properties

Methods

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : never
Parameters
$data : array<string|int, mixed>
Return values
never

compute()

Obtains the lock for the given key, then invokes the {@code $compute} callback with the current cached value (which may be {@code null} if the key did not exist in the cache). The value returned from the callback is stored in the cache and returned from this method.

public compute(string $key, callable(string, Array): TValue $compute[, int|null $ttl = null ]) : TValue
Parameters
$key : string
$compute : callable(string, Array): TValue

Receives $key and $value as parameters.

$ttl : int|null = null

Timeout in seconds. The default null $ttl value indicates no timeout.

Tags
throws
CacheException

If the $create callback throws an exception while generating the value.

Return values
TValue

computeIfAbsent()

Attempts to get the value for the given key. If the key is not found, the key is locked, the $compute callback is invoked with the key as the first parameter. The value returned from the callback is stored in the cache and returned from this method.

public computeIfAbsent(string $key, callable(string, null): TValue $compute[, int|null $ttl = null ]) : TValue
Parameters
$key : string

Cache key.

$compute : callable(string, null): TValue

Receives $key as parameter.

$ttl : int|null = null

Timeout in seconds. The default null $ttl value indicates no timeout.

Tags
throws
CacheException

If the $compute callback throws an exception while generating the value.

Return values
TValue

computeIfPresent()

Attempts to get the value for the given key. If the key exists, the key is locked, the $compute callback is invoked with the key as the first parameter and the current key value as the second parameter. The value returned from the callback is stored in the cache and returned from this method.

public computeIfPresent(string $key, callable(string, TValue): TValue $compute[, int|null $ttl = null ]) : TValue
Parameters
$key : string

Cache key.

$compute : callable(string, TValue): TValue

Receives $key and $value as parameters.

$ttl : int|null = null

Timeout in seconds. The default null $ttl value indicates no timeout.

Tags
throws
CacheException

If the $create callback throws an exception while generating the value.

Return values
TValue

delete()

The lock is obtained for the key before deleting the key.

public delete(string $key) : bool|null
Parameters
$key : string
Tags
throws
CacheException
Return values
bool|null

get()

Returns the cached value for the key or the given default value if the key does not exist.

public get(string $key[, TDefault $default = null ]) : TValue|TDefault
Parameters
$key : string

Cache key.

$default : TDefault = null

Default value returned if the key does not exist. Null by default.

Tags
template
throws
CacheException
Return values
TValue|TDefault

Resolved with null iff $default is null.

set()

The lock is obtained for the key before setting the value.

public set(string $key, TValue $value[, int|null $ttl = null ]) : void
Parameters
$key : string

Cache key.

$value : TValue

Value to cache.

$ttl : int|null = null

Timeout in seconds. The default null $ttl value indicates no timeout.

Tags
throws
CacheException
see
SerializedCache::set()

create()

private create(Closure $compute, string $key, TValue|null $value, int|null $ttl) : mixed
Parameters
$compute : Closure
$key : string
$value : TValue|null
$ttl : int|null
Tags
throws
CacheException

        
On this page

Search results