CodeIgniter v4.7 API

MockCache extends BaseHandler
in package
implements CacheInterface

Base class for cache handling

Table of Contents

Interfaces

CacheInterface

Constants

MAX_KEY_LENGTH  = PHP_INT_MAX
Maximum key length.
RESERVED_CHARACTERS  = '{}()/\@:'
Reserved characters that cannot be used in a key or tag. May be overridden by the config.

Properties

$bypass  : bool
If true, will not cache any data.
$cache  : array<string, mixed>
Mock cache storage.
$expirations  : array<string, int|null>
Expiration times.
$prefix  : string
Prefix to apply to cache keys.

Methods

assertHas()  : void
Asserts that the cache has an item named $key.
assertHasValue()  : void
Asserts that the cache has an item named $key with a value matching $value.
assertMissing()  : void
Asserts that the cache does NOT have an item named $key.
bypass()  : $this
Instructs the class to ignore all requests to cache an item, and always "miss" when checked for existing data.
clean()  : bool
Will delete all items in the entire cache.
decrement()  : bool
Performs atomic decrementation of a raw stored value.
delete()  : bool
Deletes a specific item from the cache store.
deleteMatching()  : int
Deletes items from the cache store matching a given pattern.
get()  : bool|null
Attempts to fetch an item from the cache store.
getCacheInfo()  : array<int, string>
Returns information on the entire cache.
getMetaData()  : array{expire: int|null}|null
Returns detailed information about the specific item in the cache.
increment()  : bool
Performs atomic incrementation of a raw stored value.
initialize()  : void
Takes care of any handler-specific setup that must be done.
isSupported()  : bool
Determine if the driver is supported on this system.
ping()  : bool
Check if connection is alive.
reconnect()  : bool
Reconnect to the cache server.
remember()  : bool|null
Get an item from the cache, or execute the given Closure and store the result.
save()  : bool
Saves an item to the cache store.
validateKey()  : string
Validates a cache key according to PSR-6.

Constants

MAX_KEY_LENGTH

Maximum key length.

public mixed MAX_KEY_LENGTH = PHP_INT_MAX

RESERVED_CHARACTERS

Reserved characters that cannot be used in a key or tag. May be overridden by the config.

in favor of the Cache config

public mixed RESERVED_CHARACTERS = '{}()/\@:'

From https://github.com/symfony/cache-contracts/blob/c0446463729b89dd4fa62e9aeecc80287323615d/ItemInterface.php#L43

Properties

$bypass

If true, will not cache any data.

protected bool $bypass = false

$cache

Mock cache storage.

protected array<string, mixed> $cache = []

$expirations

Expiration times.

protected array<string, int|null> $expirations = []

$prefix

Prefix to apply to cache keys.

protected string $prefix

May not be used by all handlers.

Methods

assertHas()

Asserts that the cache has an item named $key.

public assertHas(string $key) : void

The value is not checked since storing false or null values is valid.

Parameters
$key : string

assertHasValue()

Asserts that the cache has an item named $key with a value matching $value.

public assertHasValue(string $key[, mixed $value = null ]) : void
Parameters
$key : string
$value : mixed = null

assertMissing()

Asserts that the cache does NOT have an item named $key.

public assertMissing(string $key) : void
Parameters
$key : string

bypass()

Instructs the class to ignore all requests to cache an item, and always "miss" when checked for existing data.

public bypass([bool $bypass = true ]) : $this
Parameters
$bypass : bool = true
Return values
$this

clean()

Will delete all items in the entire cache.

public clean() : bool
Return values
bool

Success or failure

decrement()

Performs atomic decrementation of a raw stored value.

public decrement(string $key[, int $offset = 1 ]) : bool
Parameters
$key : string

Cache ID

$offset : int = 1

Step/value to increase by

Return values
bool

delete()

Deletes a specific item from the cache store.

public delete(string $key) : bool
Parameters
$key : string

Cache item name

Return values
bool

Success or failure

deleteMatching()

Deletes items from the cache store matching a given pattern.

public deleteMatching(string $pattern) : int
Parameters
$pattern : string

Cache items glob-style pattern

Return values
int

Number of deleted items

get()

Attempts to fetch an item from the cache store.

public get(string $key) : bool|null
Parameters
$key : string

Cache item name

Return values
bool|null

getCacheInfo()

Returns information on the entire cache.

public getCacheInfo() : array<int, string>

The information returned and the structure of the data varies depending on the handler.

Return values
array<int, string>

Keys currently present in the store

getMetaData()

Returns detailed information about the specific item in the cache.

public getMetaData(string $key) : array{expire: int|null}|null
Parameters
$key : string

Cache item name.

Return values
array{expire: int|null}|null

Returns null if the item does not exist, otherwise, array with the 'expire' key for absolute epoch expiry (or null).

increment()

Performs atomic incrementation of a raw stored value.

public increment(string $key[, int $offset = 1 ]) : bool
Parameters
$key : string

Cache ID

$offset : int = 1

Step/value to increase by

Return values
bool

initialize()

Takes care of any handler-specific setup that must be done.

public initialize() : void

isSupported()

Determine if the driver is supported on this system.

public isSupported() : bool
Return values
bool

ping()

Check if connection is alive.

public ping() : bool

Default implementation for handlers that don't require connection management. Handlers with persistent connections (Redis, Predis, Memcached) should override this.

Return values
bool

reconnect()

Reconnect to the cache server.

public reconnect() : bool

Default implementation for handlers that don't require connection management. Handlers with persistent connections (Redis, Predis, Memcached) should override this.

Return values
bool

remember()

Get an item from the cache, or execute the given Closure and store the result.

public remember(string $key, int $ttl, Closure $callback) : bool|null
Parameters
$key : string

Cache item name

$ttl : int

Time To Live, in seconds

$callback : Closure

Callback executed on cache miss

Return values
bool|null

save()

Saves an item to the cache store.

public save(string $key, mixed $value[, int $ttl = 60 ]) : bool

The $raw parameter is only utilized by Mamcache in order to allow usage of increment() and decrement().

Parameters
$key : string

Cache item name

$value : mixed

the data to save

$ttl : int = 60

Time To Live, in seconds (default 60)

Return values
bool

Success or failure

validateKey()

Validates a cache key according to PSR-6.

public static validateKey(mixed $key[, string $prefix = '' ]) : string

Keys that exceed MAX_KEY_LENGTH are hashed. From https://github.com/symfony/cache/blob/7b024c6726af21fd4984ac8d1eae2b9f3d90de88/CacheItem.php#L158

Parameters
$key : mixed

The key to validate

$prefix : string = ''

Optional prefix to include in length calculations

Tags
throws
InvalidArgumentException

When $key is not valid

Return values
string

        
On this page

Search results