Article For
2.0 2.5 3.0 3.5 4.0 4.1 4.2 5.0 5.1 5.2

Expiration Bundle

The expiration bundle serves a very simple purpose, it deletes documents whose time have passed. Usage scenarios for the Expiration Bundle include storing user sessions in RavenDB or using RavenDB as a cache.

Installation

Simply place the Raven.Bundles.Expiration.dll in the Plugins directory.

Usage

You can set the expiration date for a document using the following code:

var expiry = DateTime.Now.AddMinutes(5);
using (var session = documentStore.OpenSession())
{
	session.Store(userSession);
	session.Advanced.GetMetadataFor(userSession)["Raven-Expiration-Date"] = new RavenJValue(expiry.ToUniversalTime());
	session.SaveChanges();
}

As you can see, all we need to do is set the Raven-Expiration-Date property on the metadata for the appropriate date. And at the specified time, the document will automatically be deleted.

Note: The date must be UTC, not local time.