Friday, 4 July 2008

Velocity: Digging Deeper

I started looking properly at some Velocity bits and pieces this afternoon, including starting to write a little code against it. And I've already found one or two frustrations, or at least things that don't seem to work quite the way I want them to.

You use the CacheFactory to create an instance of a Cache. So far, so good - I like the Factory pattern. What I'm not so keen on here is that the CacheFactory's methods all have to be called on an instance e.g. instead of:
Dim cache As Cache
cache = CacheFactory.GetCache("MyCache")
you have to write:
Dim factory As CacheFactory
Dim cache As Cache

factory = New CacheFactory
cache = factory.GetCache("MyCache")
[EDIT: It came back to me at the weekend that these are called static methods, or Shared in the one true language of VB]
It's a small annoyance, but I'm a small person sometimes.

I'm going to come right out and say it: I don't get Regions. I'm completely sold on the concept of a single cross-machine cache - it solves the major issue with the ASP.NET Cache (which runs per-machine). So why then require Regions to live on a single machine? It's like they're saying "here, do this to be fault-tolerant, but to get the most out of it you have to do things that aren't fault tolerant".
It's doubly frustrating when you discover that if you want to add an item to a Velocity cache with an expiry time, you have to add it to a Region. The Cache on its' own just allows you to add an item that's there forever.

I really think dependencies are the biggest missing element in the first CTP of Velocity. The SqlCacheDependency in .NET 2.0 was the biggest enabler for caching as it meant you could run multiple web servers and keep their caches in sync with database changes without much effort. You can't do this in CTP1.

I'm interested to see Barry has proposed a session on Velocity for DDD7. That's good 'cos it means I can pick his brain for suggestions to solve some of these things!

No comments: