You are here

class KeyValueChainedExpirableFactory in Supercache 8

Same name and namespace in other branches
  1. 2.0.x src/KeyValueStore/KeyValueChainedExpirableFactory.php \Drupal\supercache\KeyValueStore\KeyValueChainedExpirableFactory

Defines the key/value store factory for the wincache/databse backend.

Hierarchy

Expanded class hierarchy of KeyValueChainedExpirableFactory

1 string reference to 'KeyValueChainedExpirableFactory'
supercache.services.yml in ./supercache.services.yml
supercache.services.yml
1 service uses KeyValueChainedExpirableFactory
keyvalue.expirable.supercache in ./supercache.services.yml
Drupal\supercache\KeyValueStore\KeyValueChainedExpirableFactory

File

src/KeyValueStore/KeyValueChainedExpirableFactory.php, line 22
Contains \Drupal\supercache\KeyValueStore\KeyValueWincacheExpirableFactory.

Namespace

Drupal\supercache\KeyValueStore
View source
class KeyValueChainedExpirableFactory implements KeyValueExpirableFactoryInterface {

  /**
   * Holds references to each instantiation so they can be terminated.
   *
   * @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[]
   */
  protected $storages = array();

  /**
   * The serialization class to use.
   *
   * @var \Drupal\Component\Serialization\SerializationInterface
   */
  protected $serializer;

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * The cache factory.
   *
   * @var CacheFactoryInterface
   */
  protected $factory;

  /**
   * Constructs this factory object.
   *
   * @param \Drupal\Component\Serialization\SerializationInterface $serializer
   *   The serialization class to use.
   * @param \Drupal\Core\Database\Connection $connection
   *   The Connection object containing the key-value tables.
   */
  function __construct(CacheFactoryInterface $factory, SerializationInterface $serializer, Connection $connection) {
    $this->serializer = $serializer;
    $this->connection = $connection;
    $this->factory = $factory;
  }
  protected $backed_by_database;

  /**
   * Not very reliabled but....
   * we want to prevent this thing
   * from triggering if the cache
   * factory is going to return
   * us a cache backend that sits
   * on top of the database...
   */
  function backedByDatabase() {
    if (!isset($this->backed_by_database)) {
      $this->backed_by_database = $this->factory
        ->get('test-binary') instanceof \Drupal\Core\Cache\DatabaseBackend;
    }
    return $this->backed_by_database;
  }

  /**
   * {@inheritdoc}
   */
  public function get($collection) {
    if (!isset($this->storages[$collection])) {

      // Do not chain if the database will
      // be taking care of caching.
      if ($this
        ->backedByDatabase()) {
        return new \Drupal\Core\KeyValueStore\DatabaseStorageExpirable($collection, $this->serializer, $this->connection);
      }
      $this->storages[$collection] = new ChainedStorageExpirable($this->factory, $collection, $this->serializer, $this->connection);
    }
    return $this->storages[$collection];
  }

  /**
   * Deletes expired items.
   */
  public function garbageCollection() {

    // No need to gargabe collect.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyValueChainedExpirableFactory::$backed_by_database protected property
KeyValueChainedExpirableFactory::$connection protected property The database connection.
KeyValueChainedExpirableFactory::$factory protected property The cache factory.
KeyValueChainedExpirableFactory::$serializer protected property The serialization class to use.
KeyValueChainedExpirableFactory::$storages protected property Holds references to each instantiation so they can be terminated.
KeyValueChainedExpirableFactory::backedByDatabase function Not very reliabled but.... we want to prevent this thing from triggering if the cache factory is going to return us a cache backend that sits on top of the database...
KeyValueChainedExpirableFactory::garbageCollection public function Deletes expired items.
KeyValueChainedExpirableFactory::get public function Constructs a new expirable key/value store for a given collection name. Overrides KeyValueExpirableFactoryInterface::get
KeyValueChainedExpirableFactory::__construct function Constructs this factory object.