You are here

function KeyvalueMongodbFactory::get in MongoDB 8

File

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

Class

KeyvalueMongodbFactory

Namespace

Drupal\mongodb

Code

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);
}