You are currently browsing legacy 2.5 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Bundle: Expiration

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.


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

var expiry = DateTime.UtcNow.AddMinutes(5);
using (var session = documentStore.OpenSession())
	session.Advanced.GetMetadataFor(userSession)["Raven-Expiration-Date"] = new RavenJValue(expiry);

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.


The date must be UTC, not local time.


When master-master replication is set between servers then the Expiration bundle should be turned on ONLY on one server, otherwise conflicts will occur.