Skip to content

CachedConfig

github-actions[bot] edited this page Oct 16, 2026 · 3 revisions

Class CachedConfig.

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.


  • Full name: \FastForward\Config\CachedConfig
  • This class is marked as final and can't be subclassed
  • This class implements: \FastForward\Config\ConfigInterface
  • This class is a Final class

Methods

__construct

Constructs a CachedConfig wrapper.

public __construct(\Psr\SimpleCache\CacheInterface $cache, \FastForward\Config\ConfigInterface $defaultConfig, bool $persistent = false, string|null $cacheKey = null): mixed

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:

Parameter Type Description
$cache \Psr\SimpleCache\CacheInterface the cache implementation used for storing configuration data
$defaultConfig \FastForward\Config\ConfigInterface the configuration source to be cached
$persistent bool whether the cache should be persistent or not
$cacheKey string|null a shared cache key, or null for an isolated key whose entries expire after 300 seconds

__invoke

Invokes the configuration and returns the cached configuration data.

public __invoke(): \FastForward\Config\ConfigInterface

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.

Return Value:

a ConfigInterface implementation containing the cached configuration data

Throws:

if the cache key is invalid


set

Sets configuration data.

public set(array|\FastForward\Config\ConfigInterface|string $key, mixed $value = null): void

This method MUST update the cached configuration data in the cache if the persistent flag is set to true.

Parameters:

Parameter Type Description
$key array|\FastForward\Config\ConfigInterface|string the configuration key or an array of key-value pairs to set
$value mixed the value to set for the specified key

Throws:

if the key is invalid


remove

Removes a configuration value by key.

public remove(mixed $key): void

This method MUST update the backend when persistent mode is enabled.

Parameters:

Parameter Type Description
$key mixed the configuration key to remove

Throws:

if the cache key is invalid


Inherited methods

__invoke

Implementing class MUST define the __invoke() method to return a ConfigInterface instance.

public __invoke(): \FastForward\Config\ConfigInterface
  • This method is abstract. Return Value:

the actual configuration instance


get

Retrieves a configuration value by key.

public get(string $key, mixed|null $default = null): mixed

Parameters:

Parameter Type Description
$key string the configuration key to retrieve
$default mixed|null the default value if the key is not found

Return Value:

the value of the configuration key or the default


has

Checks for existence of a configuration key.

public has(string $key): bool

Parameters:

Parameter Type Description
$key string the configuration key to check

Return Value:

TRUE if the key exists, FALSE otherwise


set

Sets configuration data.

public set(array|\FastForward\Config\ConfigInterface|string $key, mixed|null $value = null): void

Parameters:

Parameter Type Description
$key array|\FastForward\Config\ConfigInterface|string the key or set of keys/values to set
$value mixed|null the value to set if a single key is provided

remove

Removes a configuration key.

public remove(string $key): void

Parameters:

Parameter Type Description
$key string the configuration key to remove

toArray

Exports the entire configuration to an array.

public toArray(): array

Return Value:

the configuration as an associative array


getIterator

Retrieves an iterator for traversing the configuration data.

public getIterator(): \Traversable

Return Value:

an iterator over the configuration


Clone this wiki locally