class MultiBackend extends AbstractBackend implements BackendInterface (View source)

A multi backend, falling back to multiple backends if errors occur.

Traits

Abstracts the task of creating a BackendInterface implementation with it's options.

Constants

DATETIME_EXPIRYTIME_UNLIMITED

UNLIMITED_LIFETIME

Properties

protected FrontendInterface $cache

Reference to the cache frontend which uses this backend

from  AbstractBackend
protected string $cacheIdentifier from  AbstractBackend
protected string $identifierPrefix

A prefix to seperate stored by appliaction context and cache

from  AbstractBackend
protected int $defaultLifetime

Default lifetime of a cache entry in seconds

from  AbstractBackend
protected EnvironmentConfiguration $environmentConfiguration from  AbstractBackend
protected array $backendConfigurations

Configuration for all sub backends (each with the keys "backend" and "backendOptions")

protected BackendInterface[] $backends
protected bool $setInAllBackends
protected bool $debug
protected bool $initialized

Are the backends initialized

Methods

__construct(EnvironmentConfiguration $environmentConfiguration, array $options)

Constructs this backend

void
setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)

No description

bool
setProperty(string $propertyName, mixed $propertyValue)

No description

void
setCache(FrontendInterface $cache)

Sets a reference to the cache frontend which uses this backend

void
setDefaultLifetime(int|string $defaultLifetime)

Sets the default lifetime for this cache backend

calculateExpiryTime(int $lifetime = null)

Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.

string
getPrefixedIdentifier(string $entryIdentifier)

Returns the internally used, prefixed entry identifier for the given public entry identifier.

instantiateBackend(string $backendObjectName, array $backendOptions, EnvironmentConfiguration $environmentConfiguration)

No description

void
prepareBackends()

No description

BackendInterface|null
buildSubBackend(string $backendClassName, array $backendOptions)

No description

void
set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

No description

mixed
get(string $entryIdentifier)

No description

bool
has(string $entryIdentifier)

No description

bool
remove(string $entryIdentifier)

No description

void
flush()

No description

void
collectGarbage()

No description

void
setBackendConfigurations(array $backendConfigurations)

No description

void
setSetInAllBackends(bool $setInAllBackends)

No description

void
setDebug(bool $debug)

No description

void
setInBackend(BackendInterface $backend, string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

No description

mixed
getFromBackend(BackendInterface $backend, string $entryIdentifier)

No description

bool
backendHas(BackendInterface $backend, string $entryIdentifier)

No description

bool
removeFromBackend(BackendInterface $backend, string $entryIdentifier)

No description

void
flushBackend(BackendInterface $backend)

No description

void
handleError(Throwable $throwable)

No description

Details

__construct(EnvironmentConfiguration $environmentConfiguration, array $options)

Constructs this backend

Parameters

EnvironmentConfiguration $environmentConfiguration
array $options

Configuration options - depends on the actual backend

protected void setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)

No description

Parameters

array $properties
bool $throwExceptionIfPropertyNotSettable

Return Value

void

Exceptions

InvalidArgumentException

protected bool setProperty(string $propertyName, mixed $propertyValue)

No description

Parameters

string $propertyName
mixed $propertyValue

Return Value

bool

void setCache(FrontendInterface $cache)

Sets a reference to the cache frontend which uses this backend

Parameters

FrontendInterface $cache

The frontend for this backend

Return Value

void

void setDefaultLifetime(int|string $defaultLifetime)

Sets the default lifetime for this cache backend

Parameters

int|string $defaultLifetime

Default lifetime of this cache backend in seconds. 0 means unlimited lifetime.

Return Value

void

Exceptions

InvalidArgumentException

protected DateTime calculateExpiryTime(int $lifetime = null)

Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.

Parameters

int $lifetime

The lifetime in seconds

Return Value

DateTime

The expiry time

string getPrefixedIdentifier(string $entryIdentifier)

Returns the internally used, prefixed entry identifier for the given public entry identifier.

While Flow applications will mostly refer to the simple entry identifier, it may be necessary to know the actual identifier used by the cache backend in order to share cache entries with other applications. This method allows for retrieving it.

Note that, in case of the AbstractBackend, this method is returns just the given entry identifier.

Parameters

string $entryIdentifier

Return Value

string

protected BackendInterface instantiateBackend(string $backendObjectName, array $backendOptions, EnvironmentConfiguration $environmentConfiguration)

No description

Parameters

string $backendObjectName
array $backendOptions
EnvironmentConfiguration $environmentConfiguration

Return Value

BackendInterface

Exceptions

InvalidBackendException

protected void prepareBackends()

No description

Return Value

void

Exceptions

Throwable

protected BackendInterface|null buildSubBackend(string $backendClassName, array $backendOptions)

No description

Parameters

string $backendClassName
array $backendOptions

Return Value

BackendInterface|null

Exceptions

Throwable

void set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

No description

Parameters

string $entryIdentifier

An identifier for this specific cache entry

string $data

The data to be stored

array $tags

Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.

int $lifetime

Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.

Return Value

void

Exceptions

Throwable

mixed get(string $entryIdentifier)

No description

Parameters

string $entryIdentifier

An identifier which describes the cache entry to load

Return Value

mixed

The cache entry's content as a string or false if the cache entry could not be loaded

Exceptions

Throwable

bool has(string $entryIdentifier)

No description

Parameters

string $entryIdentifier

An identifier specifying the cache entry

Return Value

bool

true if such an entry exists, false if not

Exceptions

Throwable

bool remove(string $entryIdentifier)

No description

Parameters

string $entryIdentifier

Specifies the cache entry to remove

Return Value

bool

true if (at least) an entry could be removed or false if no entry was found

Exceptions

Throwable

void flush()

No description

Return Value

void

Exceptions

Throwable

void collectGarbage()

No description

Return Value

void

Exceptions

Throwable

protected void setBackendConfigurations(array $backendConfigurations)

No description

Parameters

array $backendConfigurations

Return Value

void

protected void setSetInAllBackends(bool $setInAllBackends)

No description

Parameters

bool $setInAllBackends

Return Value

void

protected void setDebug(bool $debug)

No description

Parameters

bool $debug

Return Value

void

protected void setInBackend(BackendInterface $backend, string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

No description

Parameters

BackendInterface $backend
string $entryIdentifier
string $data
array $tags
int $lifetime

Return Value

void

Exceptions

Exception

protected mixed getFromBackend(BackendInterface $backend, string $entryIdentifier)

No description

Parameters

BackendInterface $backend
string $entryIdentifier

Return Value

mixed

protected bool backendHas(BackendInterface $backend, string $entryIdentifier)

No description

Parameters

BackendInterface $backend
string $entryIdentifier

Return Value

bool

protected bool removeFromBackend(BackendInterface $backend, string $entryIdentifier)

No description

Parameters

BackendInterface $backend
string $entryIdentifier

Return Value

bool

protected void flushBackend(BackendInterface $backend)

No description

Parameters

BackendInterface $backend

Return Value

void

protected void handleError(Throwable $throwable)

No description

Parameters

Throwable $throwable

Return Value

void

Exceptions

Throwable