Documentation

CRM_Utils_Cache_FileCache
in package
implements CRM_Utils_Cache_Interface uses CRM_Utils_Cache_NaiveMultipleTrait, CRM_Utils_Cache_NaiveHasTrait

Class CRM_Utils_Cache_FileCache

Table of Contents

Interfaces

CRM_Utils_Cache_Interface

Constants

DEFAULT_PREFIX  = ''
DEFAULT_TIMEOUT  = 3600
MAX_KEY_LEN  = 100
Max key length to be used for file systems.

Properties

$_prefix  : string
The prefix prepended to cache keys.
$_timeout  : int
The default timeout to use.
$expiresCache  : array<string|int, mixed>
In-memory cache to optimize redundant get()s.
$valueCache  : array<string|int, mixed>
In-memory cache to optimize redundant get()s.

Methods

__construct()  : CRM_Utils_Cache_FileCache
Constructor.
clear()  : bool
Delete all values from the cache.
delete()  : bool
Delete a value from the cache.
deleteMultiple()  : bool
Deletes multiple cache items in a single operation.
flush()  : bool
Delete all values from the cache.
garbageCollection()  : bool
Performs garbage collection on a cache. Removing expired items.
get()  : mixed
Get a value from the cache.
getMultiple()  : iterable<string|int, mixed>
Obtains multiple cache items by their unique keys.
has()  : bool
Determines whether an item is present in the cache.
prefetch()  : mixed
Prefetch
set()  : bool
Set the value in the cache.
setMultiple()  : bool
Persists a set of key => value pairs in the cache, with an optional TTL.
cleanKey()  : string
cleanPrefix()  : string
getCacheDir()  : string
Get the directory for cache.
getCacheFile()  : string
getContents()  : string
Get file contents
keyPath()  : string
Full key path The prefix plus the key, used for the filename path and for temporary storage in the in-memory array.
shortenPathSegment()  : string
Shortens path segment so it fits within a maximum name length
assertIterable()  : mixed
reobjectify()  : object

Constants

DEFAULT_PREFIX

public mixed DEFAULT_PREFIX = ''

DEFAULT_TIMEOUT

public mixed DEFAULT_TIMEOUT = 3600

MAX_KEY_LEN

Max key length to be used for file systems.

public mixed MAX_KEY_LEN = 100

This applies separately to each folder-part/file-part.

PSR-16 only requires 64 chars. So anything longer is generous.

Properties

$_prefix

The prefix prepended to cache keys.

protected string $_prefix = self::DEFAULT_PREFIX

If we are using the same instance for multiple CiviCRM installs, we must have a unique prefix for each install to prevent the keys from clobbering each other.

$_timeout

The default timeout to use.

protected int $_timeout = self::DEFAULT_TIMEOUT

$expiresCache

In-memory cache to optimize redundant get()s.

protected array<string|int, mixed> $expiresCache

Note: expiresCache[$key]===NULL means cache-miss

$valueCache

In-memory cache to optimize redundant get()s.

protected array<string|int, mixed> $valueCache

Methods

clear()

Delete all values from the cache.

public clear() : bool
Return values
bool

delete()

Delete a value from the cache.

public delete(mixed $key) : bool
Parameters
$key : mixed
Return values
bool

deleteMultiple()

Deletes multiple cache items in a single operation.

public deleteMultiple(iterable<string|int, mixed> $keys) : bool
Parameters
$keys : iterable<string|int, mixed>

A list of string-based keys to be deleted.

Tags
throws
InvalidArgumentException

MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Return values
bool

True if the items were successfully removed. False if there was an error.

flush()

Delete all values from the cache.

public flush() : bool
Return values
bool

garbageCollection()

Performs garbage collection on a cache. Removing expired items.

public garbageCollection() : bool
Return values
bool

get()

Get a value from the cache.

public get(mixed $key[, mixed $default = null ]) : mixed
Parameters
$key : mixed
$default : mixed = null
Return values
mixed

The previously set value value, or $default (NULL).

getMultiple()

Obtains multiple cache items by their unique keys.

public getMultiple(iterable<string|int, mixed> $keys[, mixed $default = null ]) : iterable<string|int, mixed>
Parameters
$keys : iterable<string|int, mixed>

A list of keys that can obtained in a single operation.

$default : mixed = null

Default value to return for keys that do not exist.

Tags
throws
InvalidArgumentException

MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

Return values
iterable<string|int, mixed>

A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.

has()

Determines whether an item is present in the cache.

public has(mixed $key) : bool
Parameters
$key : mixed

The cache item key.

Return values
bool

prefetch()

Prefetch

public prefetch() : mixed

set()

Set the value in the cache.

public set(mixed $key, mixed $value[, mixed $ttl = null ]) : bool
Parameters
$key : mixed
$value : mixed
$ttl : mixed = null
Return values
bool

setMultiple()

Persists a set of key => value pairs in the cache, with an optional TTL.

public setMultiple(iterable<string|int, mixed> $values[, null|int|DateInterval $ttl = null ]) : bool
Parameters
$values : iterable<string|int, mixed>

A list of key => value pairs for a multiple-set operation.

$ttl : null|int|DateInterval = null

Optional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.

Tags
throws
InvalidArgumentException

MUST be thrown if $values is neither an array nor a Traversable, or if any of the $values are not a legal value.

Return values
bool

True on success and false on failure.

cleanKey()

protected cleanKey(string $key) : string
Parameters
$key : string
Return values
string

cleanPrefix()

protected cleanPrefix(string $prefix) : string
Parameters
$prefix : string
Return values
string

getCacheDir()

Get the directory for cache.

protected getCacheDir() : string
Return values
string

The main cache directory.

getCacheFile()

protected getCacheFile(string $key_path) : string
Parameters
$key_path : string

The prefix plus clean key.

Return values
string

The full filename path.

getContents()

Get file contents

protected getContents(string $path) : string
Parameters
$path : string
Return values
string

keyPath()

Full key path The prefix plus the key, used for the filename path and for temporary storage in the in-memory array.

protected keyPath(string $key) : string
Parameters
$key : string
Return values
string

The prefix used as a directory plus the cleaned key.

shortenPathSegment()

Shortens path segment so it fits within a maximum name length

protected shortenPathSegment(string $segment) : string
Parameters
$segment : string
Return values
string

A name shortened to a maximum length that will be safe for most file systems. As much of the original string as possible is preserved, with a unique hash attached.

reobjectify()

private reobjectify(mixed $value) : object
Parameters
$value : mixed
Return values
object

        
On this page

Search results