You are here

class KeyvalueMongodbFactory in MongoDB 8

Hierarchy

Expanded class hierarchy of KeyvalueMongodbFactory

1 string reference to 'KeyvalueMongodbFactory'
mongodb.services.yml in ./mongodb.services.yml
mongodb.services.yml
2 services use KeyvalueMongodbFactory
keyvalue.expirable.mongodb in ./mongodb.services.yml
Drupal\mongodb\KeyvalueMongodbFactory
keyvalue.mongodb in ./mongodb.services.yml
Drupal\mongodb\KeyvalueMongodbFactory

File

src/KeyvalueMongodbFactory.php, line 12
Definition of Drupal\mongodb\MongoKeyValueFactory.

Namespace

Drupal\mongodb
View source
class KeyvalueMongodbFactory {

  /**
   * @var MongoCollectionFactory $mongo
   */
  protected $mongo;

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

  /**
   * The prefix. keyvalue or keyvalue.expirable.
   *
   * @var string
   */
  protected $prefix;

  /**
   * @param MongoCollectionFactory $mongo
   * @param \Drupal\Core\Site\Settings $settings
   * @param string $prefix
   */
  function __construct(MongoCollectionFactory $mongo, Settings $settings, $prefix) {
    $this->mongo = $mongo;
    $this->settings = $settings;
    $this->prefix = $prefix;
  }
  function get($collection) {
    $mongo_collection = "{$this->prefix}.{$collection}";
    $settings = $this->settings
      ->get('mongo');
    if (isset($settings['keyvalue']['ttl'])) {
      $ttl = $settings['keyvalue']['ttl'];
    }
    else {
      $ttl = 300;
    }
    $this->mongo
      ->get($mongo_collection)
      ->ensureIndex(array(
      'expire' => 1,
    ), array(
      'expireAfterSeconds' => $ttl,
    ));
    $this->mongo
      ->get($mongo_collection)
      ->ensureIndex(array(
      '_id' => 1,
      'expire' => 1,
    ));
    return new KeyvalueMongodb($this->mongo, $collection);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyvalueMongodbFactory::$mongo protected property
KeyvalueMongodbFactory::$prefix protected property The prefix. keyvalue or keyvalue.expirable.
KeyvalueMongodbFactory::$settings protected property The settings array.
KeyvalueMongodbFactory::get function
KeyvalueMongodbFactory::__construct function