In case someone else is interested in some answers on this topic... I've been running our custom cache implementation now for more than a week with a simple key.ToString() approach similar to the Velocity implementation and it seems to be working well.
After reviewing the NH source code and using ReSharper to find all usages of the Get() and Put() methods, it seems all objects being passed have ToString() overrides that appear to be designed safely. I've concluded that key.ToString() is safe. Hope this is helpful to someone else. On Mar 23, 4:28 am, kellyb <[email protected]> wrote: > Was there something unclear about my initial post? > > I'm asking why the key is of type System.Object and what can I expect > to be passed in that value? My caching framework using key of type > System.String, and the NHContrib project's NHibernate.Caches > implementations seem to blindly call .ToString() on the passed in > key. Is that the prescribed method for handling the key in this > scenario? > > On Mar 22, 12:05 pm, Fabio Maulo <[email protected]> wrote: > > > > > > > > > Key answer > > Which is the problem to solve ? > > > On Tue, Mar 22, 2011 at 7:54 AM, kellyb <[email protected]>wrote: > > > > Is there a better place to ask this question? > > > > On Mar 18, 1:19 pm, kellyb <[email protected]> wrote: > > > > 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/NHi... > > > > > One thing that jumped out at me right off the bat is thecachekeys in > > > > the ICache interface are of type object. Our framework key's thecache > > > > 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 mycacheimplementation. > > > > > Any guidance would be appreciated - cheers > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "nhusers" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]. > > > For more options, visit this group at > > >http://groups.google.com/group/nhusers?hl=en. > > > -- > > Fabio Maulo -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
