class CachedStorage implements StorageInterface, StorageCacheInterface (View source)

Defines the cached storage.

The class gets another storage and a cache backend injected. It reads from the cache and delegates the read to the storage on a cache miss. It also handles cache invalidation.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected StorageInterface $storage

The configuration storage to be cached.

protected CacheBackendInterface $cache

The instantiated Cache backend.

protected array $findByPrefixCache

List of listAll() prefixes with their results.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StorageInterface $storage, CacheBackendInterface $cache)

Constructs a new CachedStorage.

bool
exists(string $name)

Returns whether a configuration object exists.

array|bool
read(string $name)

Reads configuration data from the storage.

array
readMultiple(array $names)

Reads configuration data from the storage.

bool
write(string $name, array $data)

Writes configuration data to the storage.

bool
delete(string $name)

Deletes a configuration object from the storage.

bool
rename(string $name, string $new_name)

Renames a configuration object in the storage.

string
encode(array $data)

Encodes configuration data into the storage-specific format.

array
decode(string $raw)

Decodes configuration data from the storage-specific format.

array
listAll(string $prefix = '')

Gets configuration object names starting with a given prefix.

array
findByPrefix(string $prefix)

Finds configuration object names starting with a given prefix.

bool
deleteAll(string $prefix = '')

Deletes configuration objects whose names start with a given prefix.

resetListCache()

Clears the static list cache.

$this
createCollection(string $collection)

Creates a collection on the storage.

array
getAllCollectionNames()

Gets the existing collections.

string
getCollectionName()

Gets the name of the current collection the storage is using.

string
getCacheKey(string $name)

Returns a cache key for a configuration name using the collection.

array
getCacheKeys(array $names)

Returns a cache key map for an array of configuration names.

string
getCollectionPrefix()

Returns a cache ID prefix to use for the collection.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StorageInterface $storage, CacheBackendInterface $cache)

Constructs a new CachedStorage.

Parameters

StorageInterface $storage

A configuration storage to be cached.

CacheBackendInterface $cache

A cache backend used to store configuration.

bool exists(string $name)

Returns whether a configuration object exists.

Parameters

string $name

The name of a configuration object to test.

Return Value

bool

TRUE if the configuration object exists, FALSE otherwise.

array|bool read(string $name)

Reads configuration data from the storage.

Parameters

string $name

The name of a configuration object to load.

Return Value

array|bool

The configuration data stored for the configuration object name. If no configuration data exists for the given name, FALSE is returned.

array readMultiple(array $names)

Reads configuration data from the storage.

Parameters

array $names

List of names of the configuration objects to load.

Return Value

array

A list of the configuration data stored for the configuration object name that could be loaded for the passed list of names.

bool write(string $name, array $data)

Writes configuration data to the storage.

Parameters

string $name

The name of a configuration object to save.

array $data

The configuration data to write.

Return Value

bool

TRUE on success, FALSE in case of an error.

Exceptions

StorageException

bool delete(string $name)

Deletes a configuration object from the storage.

Parameters

string $name

The name of a configuration object to delete.

Return Value

bool

TRUE on success, FALSE otherwise.

bool rename(string $name, string $new_name)

Renames a configuration object in the storage.

Parameters

string $name

The name of a configuration object to rename.

string $new_name

The new name of a configuration object.

Return Value

bool

TRUE on success, FALSE otherwise.

string encode(array $data)

Encodes configuration data into the storage-specific format.

This is a publicly accessible static method to allow for alternative usages in data conversion scripts and also tests.

Parameters

array $data

The configuration data to encode.

Return Value

string

The encoded configuration data.

array decode(string $raw)

Decodes configuration data from the storage-specific format.

This is a publicly accessible static method to allow for alternative usages in data conversion scripts and also tests.

Parameters

string $raw

The raw configuration data string to decode.

Return Value

array

The decoded configuration data as an associative array.

array listAll(string $prefix = '')

Gets configuration object names starting with a given prefix.

Given the following configuration objects:

  • node.type.article
  • node.type.page

Passing the prefix 'node.type.' will return an array containing the above names.

Parameters

string $prefix

(optional) The prefix to search for. If omitted, all configuration object names that exist are returned.

Return Value

array

An array containing matching configuration object names.

protected array findByPrefix(string $prefix)

Finds configuration object names starting with a given prefix.

Given the following configuration objects:

  • node.type.article
  • node.type.page

Passing the prefix 'node.type.' will return an array containing the above names.

Parameters

string $prefix

The prefix to search for

Return Value

array

An array containing matching configuration object names.

bool deleteAll(string $prefix = '')

Deletes configuration objects whose names start with a given prefix.

Given the following configuration object names:

  • node.type.article
  • node.type.page

Passing the prefix 'node.type.' will delete the above configuration objects.

Parameters

string $prefix

(optional) The prefix to search for. If omitted, all configuration objects that exist will be deleted.

Return Value

bool

TRUE on success, FALSE otherwise.

resetListCache()

Clears the static list cache.

$this createCollection(string $collection)

Creates a collection on the storage.

A configuration storage can contain multiple sets of configuration objects in partitioned collections. The collection name identifies the current collection used.

Implementations of this method must provide a new instance to avoid side effects caused by the fact that Config objects have their storage injected.

Parameters

string $collection

The collection name. Valid collection names conform to the following regex [a-zA-Z_.]. A storage does not need to have a collection set. However, if a collection is set, then storage should use it to store configuration in a way that allows retrieval of configuration for a particular collection.

Return Value

$this

A new instance of the storage backend with the collection set.

array getAllCollectionNames()

Gets the existing collections.

A configuration storage can contain multiple sets of configuration objects in partitioned collections. The collection key name identifies the current collection used.

Return Value

array

An array of existing collection names.

string getCollectionName()

Gets the name of the current collection the storage is using.

Return Value

string

The current collection name.

protected string getCacheKey(string $name)

Returns a cache key for a configuration name using the collection.

Parameters

string $name

The configuration name.

Return Value

string

The cache key for the configuration name.

protected array getCacheKeys(array $names)

Returns a cache key map for an array of configuration names.

Parameters

array $names

The configuration names.

Return Value

array

An array of cache keys keyed by configuration names.

protected string getCollectionPrefix()

Returns a cache ID prefix to use for the collection.

Return Value

string

The cache ID prefix.