Class CachedConfig.
Description
Provides a cached implementation of a configuration source. This class SHALL attempt to cache the configuration output of the decorated ConfigInterface instance. It SHALL lazily initialize and retrieve cached configuration data upon invocation.
Interfaces
Properties
Methods
Constructs a CachedConfig wrapper.
Invokes the configuration and returns the cached configuration data.
Retrieves a configuration value by key.
Retrieves an iterator for traversing the configuration data.
Checks for existence of a configuration key.
Removes a configuration value by key.
Sets configuration data.
Exports the entire configuration to an array.
Retrieves or initializes the configuration instance.
Persists a local mutation when write-through mode is enabled.
private
CacheInterface
$cache
private
string
$cacheKey
private
int|null
$cacheTtl
private
ConfigInterface|null
$config
=
null
Description
holds the loaded configuration instance
private
ConfigInterface
$defaultConfig
private
bool
$persistent
=
false
Constructs a CachedConfig wrapper.
public
__construct(CacheInterface
$cache, ConfigInterface
$defaultConfig[,
bool
$persistent = false][,
string|null
$cacheKey = null]) : mixed
Description
This constructor SHALL accept a PSR-16 cache implementation and a configuration instance to be cached. It MUST defer reading and writing the configuration until invoked.
Parameters
$cache
:
CacheInterface
Description
the cache implementation used for storing configuration data
Description
the configuration source to be cached
$persistent
:
bool
=
false
Description
whether the cache should be persistent or not
$cacheKey
:
string|null
=
null
Description
a shared cache key, or null for an isolated key whose entries expire after 300 seconds
Invokes the configuration and returns the cached configuration data.
public
__invoke() : ConfigInterface
Description
A usable cache entry MUST be returned without resolving the source. A miss or unusable entry SHALL resolve the source and attempt to cache it. A failed initial write MUST NOT discard source data. This method MUST return a ConfigInterface implementation containing the cached configuration data.
Description
if the cache key is invalid
Return values
Description
a ConfigInterface implementation containing the cached configuration data
Retrieves a configuration value by key.
public
get(
string
$key[,
mixed|null
$default = null]) : mixed
Parameters
$key
:
string
Description
the configuration key to retrieve
$default
:
mixed|null
=
null
Description
the default value if the key is not found
Return values
Description
the value of the configuration key or the default
Retrieves an iterator for traversing the configuration data.
public
getIterator() : Traversable
Return values
Description
an iterator over the configuration
Checks for existence of a configuration key.
public
has(
string
$key) : bool
Parameters
$key
:
string
Description
the configuration key to check
Return values
Description
TRUE if the key exists, FALSE otherwise
Removes a configuration value by key.
public
remove(
mixed
$key) : void
Description
This method MUST update the backend when persistent mode is enabled.
Parameters
$key
:
mixed
Description
the configuration key to remove
Description
if the cache key is invalid
Description
if a persistent write fails; the local change is retained
Sets configuration data.
public
set(
array<string|int, mixed>|ConfigInterface|string
$key[,
mixed
$value = null]) : void
Description
This method MUST update the cached configuration data in the cache if the persistent flag is set to true.
Parameters
Description
the configuration key or an array of key-value pairs to set
$value
:
mixed
=
null
Description
the value to set for the specified key
Description
if the key is invalid
Description
if a persistent write fails; the local change is retained
Exports the entire configuration to an array.
public
toArray() : array<string|int, mixed>
Return values
Description
the configuration as an associative array
Retrieves or initializes the configuration instance.
private
getConfig() : ConfigInterface
Return values
Description
the lazily-loaded configuration object
Persists a local mutation when write-through mode is enabled.
private
persistConfig(ConfigInterface
$config) : void
Parameters
Description
the locally updated configuration
Description
if the backend refuses the write