You are currently browsing legacy 1.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

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.