You are here

final class MemoryCacheFactory in Apigee Edge 8

Definition of the Apigee Edge memory cache factory service.

Hierarchy

Expanded class hierarchy of MemoryCacheFactory

1 string reference to 'MemoryCacheFactory'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses MemoryCacheFactory
apigee_edge.cache.memory_cache_factory in ./apigee_edge.services.yml
Drupal\apigee_edge\MemoryCacheFactory

File

src/MemoryCacheFactory.php, line 29

Namespace

Drupal\apigee_edge
View source
final class MemoryCacheFactory implements MemoryCacheFactoryInterface {

  /**
   * The default cache bin prefix.
   *
   * @var string
   */
  private const DEFAULT_CACHE_BIN_PREFIX = 'apigee_edge';

  /**
   * Module specific cache bin prefix.
   *
   * @var string
   */
  private $prefix;

  /**
   * Instantiated memory cache bins.
   *
   * @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface
   */
  private $bins;

  /**
   * MemoryCacheFactory constructor.
   *
   * @param string|null $prefix
   *   (Optional) Module specific prefix for the bin.
   */
  public function __construct(?string $prefix = NULL) {
    $this->prefix = $prefix ?? static::DEFAULT_CACHE_BIN_PREFIX;
  }

  /**
   * {@inheritdoc}
   */
  public function get($bin) : MemoryCacheInterface {
    $bin = "{$this->prefix}_{$bin}";
    if (!isset($this->bins[$bin])) {
      $this->bins[$bin] = new MemoryCache();
    }
    return $this->bins[$bin];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemoryCacheFactory::$bins private property Instantiated memory cache bins.
MemoryCacheFactory::$prefix private property Module specific cache bin prefix.
MemoryCacheFactory::DEFAULT_CACHE_BIN_PREFIX private constant The default cache bin prefix.
MemoryCacheFactory::get public function Gets a memory cache backend class for a given cache bin. Overrides MemoryCacheFactoryInterface::get
MemoryCacheFactory::__construct public function MemoryCacheFactory constructor.