You are here

class CacheBackendMongodbFactory in MongoDB 8

Factory for CacheBackendMongodb objects.

Hierarchy

Expanded class hierarchy of CacheBackendMongodbFactory

See also

\Drupal\Core\Cache\CacheFactory

1 string reference to 'CacheBackendMongodbFactory'
mongodb.services.yml in ./mongodb.services.yml
mongodb.services.yml
1 service uses CacheBackendMongodbFactory
cache.backend.mongodb in ./mongodb.services.yml
Drupal\mongodb\CacheBackendMongodbFactory

File

src/CacheBackendMongodbFactory.php, line 18
Contains \Drupal\Cache\mongodb\CacheBackendMongodbFactory.

Namespace

Drupal\mongodb
View source
class CacheBackendMongodbFactory {

  /**
   * The MongoDB database object.
   *
   * @var \Drupal\mongodb\MongoCollectionFactory
   */
  protected $mongo;

  /**
   * The settings array.
   *
   * @var \Drupal\Core\Site\Settings
   */
  protected $settings;

  /**
   * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
   */
  protected $checksumProvider;

  /**
   * Constructs the CacheBackendMongodbFactory object.
   *
   * @param \Drupal\mongodb\MongoCollectionFactory $mongo
   */
  function __construct(MongoCollectionFactory $mongo, Settings $settings, CacheTagsChecksumInterface $checksum_provider) {
    $this->mongo = $mongo;
    $this->settings = $settings;
    $this->checksumProvider = $checksum_provider;
  }

  /**
   * Gets CacheBackendMongodb for the specified cache bin.
   *
   * @param $bin
   *   The cache bin for which the object is created.
   *
   * @return \Drupal\mongodb\CacheBackendMongodb
   *   The cache backend object for the specified cache bin.
   */
  function get($bin) {
    if ($bin != 'cache') {
      $bin = 'cache_' . $bin;
    }
    $collection = $this->mongo
      ->get($bin);
    $collection
      ->ensureIndex(array(
      'tags' => 1,
    ));
    $settings = $this->settings
      ->get('mongo');
    if (isset($settings['cache']['ttl'])) {
      $ttl = $settings['cache']['ttl'];
    }
    else {
      $ttl = 300;
    }
    $collection
      ->ensureIndex(array(
      'expire' => 1,
    ), array(
      'expireAfterSeconds' => $ttl,
    ));
    return new CacheBackendMongodb($this->mongo
      ->get($bin), $this->checksumProvider);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheBackendMongodbFactory::$checksumProvider protected property
CacheBackendMongodbFactory::$mongo protected property The MongoDB database object.
CacheBackendMongodbFactory::$settings protected property The settings array.
CacheBackendMongodbFactory::get function Gets CacheBackendMongodb for the specified cache bin.
CacheBackendMongodbFactory::__construct function Constructs the CacheBackendMongodbFactory object.