开发者

Key Question on Custom ICache Implementation

We have our own caching framework that works well and we like it. We'd like to wire it up to NHibernate rather than take a dependency one of the other caching implementations for NH.

I've written an implementation of NHibernate.Cache.ICache that bridges our framework with NH. I based my implementation almost entirely on this:

https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Caches/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs

One thing that jumped out at me right off the bat is the cache keys in the ICache interface are of type object. Our framework key's the cache using strings. I noticed the Velocity implementation above just does a .ToString() on the key instance that's passed to the Get(object key) and Put(object key) methods. That made me a little nervous.

In my testing it appears the "key" object is of type string and it's the entity name.

My questions:

  • Is blindly calling .ToString() on the key instance a safe approach (I'm checking for null)?
  • If this implementation is indeed safe, does that mean it's always a string?
  • If this is always a string, then why is this of type object?

The NH guys are smarter than me, so the fact it's of type object makes me as开发者_开发百科sume there's something I'm missing here. I really don't want to introduce some obscure, random session management bug with unsafe key usage in my cache implementation.

Any guidance would be appreciated - cheers


I didn't get any responses here, nor on the NH user groups thread [1]. I've concluded that calling key.ToString() in our custom implementation is safe, but I'm sad I didn't get some official guidance on this :(

See the user group thread for a bit more details.

Cheers

[1] http://groups.google.com/group/nhusers/browse_thread/thread/6d47ab21e85eb9b7/988ad6046528e7bc?lnk=gst&q=Custom+Cache#988ad6046528e7bc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜