RavenDB, I love it’s aggressive caching.

ASP.NET MVC,RavenDB 28 November 2011 | 2 Comments

The project I’m using RavenDB is starting to the near the final phase. I’ve now been profiling pages and optimising my sillier bits of code.

One thing the site does is make ALOT of queries per page load that have to be (or near enough) dynamic pulling data from RavenDB for display.

When starting the project I decided to go the route of optimising the website later rather than get bogged down with it now and have to figure a way of disabling it for development.

Today I started optimising and making sure most public facing queries are cached. I installed memcached and started about writing some code to persist expensive queries. Then it hit me. I remember Ayende blogging about how RavenDB does do its own caching but offers more advanced options, so I started exploring the API (which is wonderfully organised into “basic stuff” and “advanced stuff that you might need”.

I threw memcached away and this is what I found through exploring the API and Google’ing for Ayende’s blog (see here).

[ChildActionOnly]
public ActionResult Testimonials(string type)
{
	using (Session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(10)))
	{
		var testimonials = Session.Query<Testimonial, Testimonials_QueryIndex>()
			.Where(x => x.Typee == type)
			.OrderBy(x => x.Sort)
			.Take(10)
			.ToList();

		return View(testimonials);
	}
}

Its so beautifully self explanatory to another reader and it required so little work to write.

Cheers RavenDB team!

2 Responses on “RavenDB, I love it’s aggressive caching.”

  1. Justin A says:

    Ayende also has nice video he did showing various aggressive caching options with RavenDB: http://www.youtube.com/watch?v=d4Fx-_7S9pU

    The code from that video is here: https://github.com/PureKrome/RavenOverflow

    GL!
    (and don’t be afraid to jump into Jabbr.Net (online chat) to chat about RavenDb / ASP.NET stuff)

Trackbacks/Pingbacks

  1. […] my earlier “RavenDB, I love it’s aggressive caching.” post, I made a fatal mistake in my coding for the caching scenario, I forgot about stale […]

Leave a Reply