abstract class AbstractCacheFactory implements CacheFactory (View source)

Abstract implementation of CacheFactory which provides methods to easily instantiate PSR6 and PSR16 cache adapters.

Properties

protected LoggerInterface|null $logger

Methods

public
__construct(LoggerInterface|null $logger = null)

No description

protected
CacheInterface
createCache(string $class, array $args, bool $useInjector = true)

Creates an object with a PSR-16 interface, usually from a PSR-6 class name.

protected
CacheInterface
prepareCacheForUse(CacheInterface $cacheAdapter, bool $useInjector)

Prepare a cache adapter for use.

protected
CacheInterface
instantiateCache(string $class, array $args, bool $useInjector)

Instantiates a cache adapter, either via the dependency injector or using the new keyword.

protected
bool
addLogger(CacheInterface $cache)

No description

Details

__construct(LoggerInterface|null $logger = null)

No description

Parameters

LoggerInterface|null $logger

Logger instance to assign

protected CacheInterface createCache(string $class, array $args, bool $useInjector = true)

Creates an object with a PSR-16 interface, usually from a PSR-6 class name.

Quick explanation of caching standards:

  • Symfony cache implements the PSR-6 standard
  • Symfony provides adapters which wrap a PSR-6 backend with a PSR-16 interface
  • Silverstripe uses the PSR-16 interface to interact with caches. It does not directly interact with the PSR-6 classes
  • Psr\SimpleCache\CacheInterface is the php interface of the PSR-16 standard. All concrete cache classes Silverstripe code interacts with should implement this interface

Further reading:

Parameters

string $class
array $args
bool $useInjector

Return Value

CacheInterface

protected CacheInterface prepareCacheForUse(CacheInterface $cacheAdapter, bool $useInjector)

Prepare a cache adapter for use.

This wraps a PSR6 adapter inside a PSR16 one. It also adds the loggers.

Parameters

CacheInterface $cacheAdapter
bool $useInjector

Return Value

CacheInterface

protected CacheInterface instantiateCache(string $class, array $args, bool $useInjector)

Instantiates a cache adapter, either via the dependency injector or using the new keyword.

Parameters

string $class
array $args
bool $useInjector

Return Value

CacheInterface

protected bool addLogger(CacheInterface $cache)

No description

Parameters

CacheInterface $cache

Return Value

bool