You are here

function CacheBackendMongodbFactory::get in MongoDB 8

Gets CacheBackendMongodb for the specified cache bin.

Parameters

$bin: The cache bin for which the object is created.

Return value

\Drupal\mongodb\CacheBackendMongodb The cache backend object for the specified cache bin.

File

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

Class

CacheBackendMongodbFactory
Factory for CacheBackendMongodb objects.

Namespace

Drupal\mongodb

Code

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