Ayende @ Rahien

It's a girl

You can’t cache DateTime.Now

One of the things that were itching me was the fact that it seems that not all the queries in RaccoonBlog were hitting the cache. Oh, it is more than fast enough, but I couldn’t really figure out what is going on there. Then again, it was never important enough for me to dig in.

I was busy doing the profiling stuff for RavenDB and I used RaccoonBlog as my testing ground, when I realized what the problem was:

image

Everything was working just fine, the problem was here:

image

Do you get the light bulb moment that I had? I was using Now in a query, and since Now by definition changes, we keep generating new queries, which can’t be cached, etc.

I changed all of the queries that contained Now to:

image

Which means that it would only use a different value every minute. Once I fixed that, I still saw that there was a caching problem, which led me to discover that there was an error in how we calculated etags for dynamic indexes after they have been promoted. Even a very basic profiling tool helped us fix two separate bugs (in Raccoon Blog and in RavenDB).

Comments

João Bragança
06/28/2011 05:42 PM by
João Bragança

Do you plan on leaving the profiler running on your blog indefinitely?

Ayende Rahien
06/28/2011 07:34 PM by
Ayende Rahien

João , Highly likely, why?

Chistian Horsdal
06/29/2011 08:39 PM by
Chistian Horsdal

Seems like a case where Now should have been hidden in a domain abstraction would have meant one place to dó the fix. Not to mention testability

Ryan Heath
06/30/2011 10:32 AM by
Ryan Heath

We talked about this at the ravendb maillist. You would not have run into this problem when a Post is "by definition" not deleted and public (own collection). Of course you then need to take care of future posts and how to handle deleted posts, but I see those operations as 'tiny points in time' while quering public posts is something that needs to be 'fast and sound' all the time. ;)

// Ryan

Comments have been closed on this topic.