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 assume 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