Shm
Shm
The PHP-SHM (shared memory) cache backend.
This is the absolute fastest caching backend.
There are no configuration options required for the backend.
Constants
GC_KEY
private const GC_KEY = '__garbage_collection__'
Properties
weight
protected int $weight
public $
public $
keepalive
private bool $keepalive
indexKey
private int $indexKey
locks
private array $locks
Methods
available
public available(): bool
init
Initializes the shared memory cache backend for a given namespace.
public init(string $namespace): void
Parameters
Parameter | Type | Description |
---|---|---|
$namespace | string | the namespace for the cache backend |
close
Closes the shared memory cache.
public close(): bool
has
Check if a key exists in the shared memory cache.
public has(string $key, bool $check_empty = false): bool
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to check |
$check_empty | bool | whether to check if the data associated with the key is empty |
get
Retrieves the value associated with the given key from the cache.
public get(string $key): mixed
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to retrieve the value for |
set
Sets a value in the shared memory cache.
public set(string $key, mixed $value, int $timeout = 0): bool
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to store the value under |
$value | mixed | the value to be stored |
$timeout | int | The timeout for the value in seconds. Default is 0 (no timeout). |
remove
Remove a value from the shared memory cache.
public remove(string $key): bool
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key of the value to remove |
clear
Clears the shared memory cache.
public clear(): bool
toArray
Converts the cache data to an array.
public toArray(): void
count
Returns the number of items in the cache.
public count(): int
lock
Locks a cache entry for exclusive access.
public lock(string $key): bool
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key of the cache entry |
unlock
Unlock a lock for a given key.
public unlock(string $key): bool
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key of the lock to unlock |
findFirstAvailableAddress
private findFirstAvailableAddress(array $index): int
Parameters
Parameter | Type | Description |
---|---|---|
$index | array |
getIndex
Retrieves the index from the shared memory.
private getIndex(): void
getAddr
Retrieves the address of a key in the cache.
private getAddr(string $key, bool $create = false): int
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to retrieve the address for |
$create | bool | whether to create the key if it doesn't exist |
addIndex
Adds an index for the given key in the shared memory cache backend.
private addIndex(string $key): int
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to add an index for |
removeIndex
Remove an entry from the cache index.
private removeIndex(string $key): bool
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key of the entry to be removed |
infoByAddr
Retrieves information stored in shared memory by address.
private infoByAddr(int $addr, bool $noKeepalive = false, bool $): void
Parameters
Parameter | Type | Description |
---|---|---|
$addr | int | the address of the shared memory variable |
$noKeepalive | bool | |
$ | bool |
infoByKey
Retrieves information about a cache entry by its key.
private infoByKey(string $key, bool $): void
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key of the cache entry |
$ | bool |
Generated by Hazaar API Doc Generator