function MongoDbStore::createTtlIndex
Creates a TTL index to automatically remove expired locks.
If the gcProbability option is set higher than 0.0 (defaults to 0.001); there is a chance this will be called on self::save().
Otherwise; this should be called once manually during database setup.
Alternatively the TTL index can be created manually on the database:
db.lock.createIndex( { "expires_at": 1 }, { "expireAfterSeconds": 0 } )
Please note, expires_at is based on the application server. If the database time differs; a lock could be cleaned up before it has expired. To ensure locks don't expire prematurely; the lock TTL should be set with enough extra time to account for any clock drift between nodes.
A TTL index MUST BE used to automatically clean up expired locks.
Throws
UnsupportedException if options are not supported by the selected server
MongoInvalidArgumentException for parameter/option parsing errors
DriverRuntimeException for other driver errors (e.g. connection errors)
See also
http://docs.mongodb.org/manual/tutorial/expire-data/
1 call to MongoDbStore::createTtlIndex()
- MongoDbStore::save in vendor/
symfony/ lock/ Store/ MongoDbStore.php
File
-
vendor/
symfony/ lock/ Store/ MongoDbStore.php, line 202
Class
- MongoDbStore
- MongoDbStore is a StoreInterface implementation using MongoDB as a storage engine. Support for MongoDB server >=2.2 due to use of TTL indexes.
Namespace
Symfony\Component\Lock\StoreCode
public function createTtlIndex(int $expireAfterSeconds = 0) : void {
$server = $this->getManager()
->selectServer();
$server->executeCommand($this->options['database'], new Command([
'createIndexes' => $this->options['collection'],
'indexes' => [
[
'key' => [
'expires_at' => 1,
],
'name' => 'expires_at_1',
'expireAfterSeconds' => $expireAfterSeconds,
],
],
]));
}