Aggressive caching: Pacified

time to read 2 min | 360 words

RavenDB’s aggressive caching allows RavenDB Clients to skip going to the server and  serve requests directly off the client cache. That means that you can answer queries very  quickly, because you never even have to leave your process memory space.

The downside to that was, of course, that you might be showing information that have changed behind your back.

That is why we usually wrote aggressive caching code like this:

using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
   var user =  session.Load<User>("users/1");

We gave it some duration in which it was okay to skip going to the server. So we had a maximum of 5 minutes when we had the cached information in place.

That was nice, but it was awkward. And not really nice thing to do in general. In particular, it meant that you had to wait 5 minutes for things to actually show up in the application. That can be... frustrating, because it looks like the system isn’t really doing something. On the other hand, it also means that you still have to query the server when the duration is over, and by necessity, the durations are relatively short.

We decided to change that. Now, when you are using aggressive caching, RavenDB will automatically subscribe to changes from the server. When that happens, we will be able to use the notifications to know when we need to re-check on the server.

That means that you can set an aggressive cache duration of much longer period, and that we will know, automatically and without you needing to do anything.

It is a small touch, but an important one. Things just get better Smile.