Skip to content

Instantly share code, notes, and snippets.

@alistairjevans
Last active May 1, 2019 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alistairjevans/2fc30366be03015d24a0f719731c3741 to your computer and use it in GitHub Desktop.
Save alistairjevans/2fc30366be03015d24a0f719731c3741 to your computer and use it in GitHub Desktop.
LockModel with a TTL Index
public class LockModel
{
public string Id { get; set; }
/// <summary>
/// I'm going to set this to the moment in time when the lock should be cleared.
/// </summary>
public DateTime ExpireAt { get; set; }
}
// In our LockProvider constructor...
// Specify a TTL index on the ExpiryPoint field.
collection.Indexes.CreateOne(new CreateIndexModel<LockModel>(
Builders<LockModel>.IndexKeys.Ascending(l => l.ExpireAt),
new CreateIndexOptions
{
ExpireAfter = TimeSpan.Zero
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment