class SwooleStore implements CanFlushLocks, LockProvider, Store

Constants

EVICTION_POLICY_LRU

EVICTION_POLICY_LFU

EVICTION_POLICY_TTL

EVICTION_POLICY_NOEVICTION

protected USER_PREFIX

protected INTERVAL_PREFIX

protected INTERVAL_INDEX_PREFIX

protected INTERVAL_INDEX_SHARDS

protected INTERVAL_REFRESH_CLAIM_TIMEOUT

protected LOCK_PREFIX

Properties

protected SwooleTable $table
protected array<string, true> $intervals

Locally registered interval cache keys.

Methods

__construct(SwooleTableState $state, float $memoryLimitBuffer, string $evictionPolicy, float $evictionProportion, SerializableClassPolicy $serializableClassPolicy = new SerializableClassPolicy())

Create a new Swoole store.

mixed
get(string $key)

Retrieve an item from the cache by key.

bool
hasLocalInterval(string $key)

Determine if the key is a local interval.

array
many(array $keys)

Retrieve multiple items from the cache by key.

bool
put(string $key, mixed $value, int $seconds)

Store an item in the cache for a given number of seconds.

bool
putMany(array $values, int $seconds)

Store multiple items in the cache for a given number of seconds.

bool
add(string $key, mixed $value, int $seconds)

Store an item in the cache if the key doesn't exist.

bool|int
increment(string $key, int $value = 1)

Increment the value of an item in the cache.

bool|int
decrement(string $key, int $value = 1)

Decrement the value of an item in the cache.

bool
forever(string $key, mixed $value)

Store an item in the cache indefinitely.

bool
touch(string $key, int $seconds)

Adjust the expiration time of a cached item.

void
interval(string $key, Closure $resolver, int $seconds)

Register a cache key that should be refreshed at a given interval in seconds.

void
refreshIntervalCaches()

Refresh all of the applicable interval caches.

bool
intervalShouldBeRefreshed(array $metadata, float $now)

Determine if the given interval record should be refreshed.

bool
forget(string $key)

Remove an item from the cache.

bool
flush()

Remove all items from the cache.

bool
supportsFlushingLocks()

Determine if the store can currently flush locks.

bool
flushLocks()

Remove all locks from the store.

lock(string $name, int $seconds = 0, string|null $owner = null)

Get a lock instance.

restoreLock(string $name, string $owner)

Restore a lock instance using the owner identifier.

bool
hasSeparateLockStore()

Determine if the lock store is separate from the cache store.

bool
acquireLock(string $name, string $owner, int $seconds)

Attempt to acquire a lock.

bool
releaseLock(string $name, string $owner)

Release a lock if it is owned by the given owner.

string|null
getLockOwner(string $name)

Get the current lock owner.

bool
refreshLock(string $name, string $owner, int $seconds)

Refresh a lock's TTL.

float|null
getLockRemainingLifetime(string $name)

Get the remaining lock lifetime in seconds.

void
forceReleaseLock(string $name)

Force a lock to release.

bool
recordIsFalseOrExpired(array|false $record)

Determine if the record is missing or expired.

string
getPrefix()

Get the cache key prefix.

void
evictRecords()

Evict records.

void
evictRecordsIfNeeded()

Evict records if the table is near its memory limit.

float
getCurrentTimestamp()

Get the current UNIX timestamp, with microsecond.

bool
memoryLimitIsReached()

Determine if the memory limit is reached.

int
removeRecordsByEvictionPolicy()

Remove records by the configured eviction policy.

int
removeRecordsByLRU()

Remove records by least recently used.

int
removeRecordsByLFU()

Remove records by least frequently used.

int
removeRecordsByTTL()

Remove records by TTL.

int
handleRecordsEviction(string $column)

Handle records eviction.

int
compare($left, $right)

No description

Details

at line 58
__construct(SwooleTableState $state, float $memoryLimitBuffer, string $evictionPolicy, float $evictionProportion, SerializableClassPolicy $serializableClassPolicy = new SerializableClassPolicy())

Create a new Swoole store.

Parameters

SwooleTableState $state
float $memoryLimitBuffer
string $evictionPolicy
float $evictionProportion
SerializableClassPolicy $serializableClassPolicy

at line 71
mixed get(string $key)

Retrieve an item from the cache by key.

Parameters

string $key

Return Value

mixed

at line 102
protected bool hasLocalInterval(string $key)

Determine if the key is a local interval.

Parameters

string $key

Return Value

bool

at line 111
array many(array $keys)

Retrieve multiple items from the cache by key.

Items not found in the cache will have a null value.

Parameters

array $keys

Return Value

array

at line 119
bool put(string $key, mixed $value, int $seconds)

Store an item in the cache for a given number of seconds.

Parameters

string $key
mixed $value
int $seconds

Return Value

bool

at line 131
bool putMany(array $values, int $seconds)

Store multiple items in the cache for a given number of seconds.

Parameters

array $values
int $seconds

Return Value

bool

at line 145
bool add(string $key, mixed $value, int $seconds)

Store an item in the cache if the key doesn't exist.

Parameters

string $key
mixed $value
int $seconds

Return Value

bool

at line 171
bool|int increment(string $key, int $value = 1)

Increment the value of an item in the cache.

Parameters

string $key
int $value

Return Value

bool|int

at line 204
bool|int decrement(string $key, int $value = 1)

Decrement the value of an item in the cache.

Parameters

string $key
int $value

Return Value

bool|int

at line 212
bool forever(string $key, mixed $value)

Store an item in the cache indefinitely.

Parameters

string $key
mixed $value

Return Value

bool

at line 235
bool touch(string $key, int $seconds)

Adjust the expiration time of a cached item.

Parameters

string $key
int $seconds

Return Value

bool

at line 259
void interval(string $key, Closure $resolver, int $seconds)

Register a cache key that should be refreshed at a given interval in seconds.

Parameters

string $key
Closure $resolver
int $seconds

Return Value

void

at line 303
void refreshIntervalCaches()

Refresh all of the applicable interval caches.

Return Value

void

at line 313
protected bool intervalShouldBeRefreshed(array $metadata, float $now)

Determine if the given interval record should be refreshed.

Parameters

array $metadata
float $now

Return Value

bool

at line 322
bool forget(string $key)

Remove an item from the cache.

Parameters

string $key

Return Value

bool

at line 335
bool flush()

Remove all items from the cache.

Return Value

bool

at line 353
bool supportsFlushingLocks()

Determine if the store can currently flush locks.

Return Value

bool

at line 363
bool flushLocks()

Remove all locks from the store.

Return Value

bool

Exceptions

RuntimeException

at line 383
Lock lock(string $name, int $seconds = 0, string|null $owner = null)

Get a lock instance.

Parameters

string $name
int $seconds
string|null $owner

Return Value

Lock

at line 391
Lock restoreLock(string $name, string $owner)

Restore a lock instance using the owner identifier.

Parameters

string $name
string $owner

Return Value

Lock

at line 399
bool hasSeparateLockStore()

Determine if the lock store is separate from the cache store.

Return Value

bool

at line 407
bool acquireLock(string $name, string $owner, int $seconds)

Attempt to acquire a lock.

Parameters

string $name
string $owner
int $seconds

Return Value

bool

at line 429
bool releaseLock(string $name, string $owner)

Release a lock if it is owned by the given owner.

Parameters

string $name
string $owner

Return Value

bool

at line 455
string|null getLockOwner(string $name)

Get the current lock owner.

Parameters

string $name

Return Value

string|null

at line 467
bool refreshLock(string $name, string $owner, int $seconds)

Refresh a lock's TTL.

Parameters

string $name
string $owner
int $seconds

Return Value

bool

at line 487
float|null getLockRemainingLifetime(string $name)

Get the remaining lock lifetime in seconds.

Parameters

string $name

Return Value

float|null

at line 501
void forceReleaseLock(string $name)

Force a lock to release.

Parameters

string $name

Return Value

void

at line 511
protected bool recordIsFalseOrExpired(array|false $record)

Determine if the record is missing or expired.

Parameters

array|false $record

Return Value

bool

at line 519
string getPrefix()

Get the cache key prefix.

Return Value

string

at line 527
void evictRecords()

Evict records.

Return Value

void

at line 545
protected void evictRecordsIfNeeded()

Evict records if the table is near its memory limit.

Return Value

void

at line 557
protected float getCurrentTimestamp()

Get the current UNIX timestamp, with microsecond.

Return Value

float

at line 567
protected bool memoryLimitIsReached()

Determine if the memory limit is reached.

Return Value

bool

at line 580
protected int removeRecordsByEvictionPolicy()

Remove records by the configured eviction policy.

Return Value

int

at line 604
protected int removeRecordsByLRU()

Remove records by least recently used.

Return Value

int

at line 612
protected int removeRecordsByLFU()

Remove records by least frequently used.

Return Value

int

at line 620
protected int removeRecordsByTTL()

Remove records by TTL.

Return Value

int

at line 628
protected int handleRecordsEviction(string $column)

Handle records eviction.

Parameters

string $column

Return Value

int

at line 637
protected int compare($left, $right)

No description

Parameters

$left
$right

Return Value

int