Thanks Tim. "Why not just fetch and update the object in question with the data you received from some other source, and the cache (and eventually the db) will be up to date."
I guess my point is, that when I receive the object via the Network, it was because somebody else on the Network has already just recently committed that object to the database, and I'm being notified of that fact. Imagine a Doctor's office with 20 people running the software connected via P2P. One person saves an object and notifies all the other ones of that fact via the Network. What I'm trying to avoid is then all 20 workstations going and selecting that object out of the database. They just got it off the network, so all the data the client needs, it already has. It seems to me the better approach would be to receive the object off the network, and have it "absorb" into my system completely, and not have to make another trip from each client to the database in order to verify the correctness of the object. Just treat it as the "gospel" master object and replace any other previous version of that object with the one received off the network. Why does it seem like people want to challenge everything I'm doing, instead of considering the possibility I might have a good idea or a unique need? "If you insert into that cache manually from some other source, you completely violate that contract." What I'm saying is that by providing a SessionFactory.Evict() method, hasn't this "contract" essentially been violated already? And if it has, then why not enjoy this and expand on it to let it be a 2 way street? H On Aug 5, 9:32 am, Tim Hoolihan <[email protected]> wrote: > The discussion seems to be missing a fundamental point of L2 cache. > If you get an object, or collection of objects via NHibernate with L2 > cache, you don't know or care if the object is coming from the cache > or the database. The assumption is, that if you do not hit the > database that you are getting an up-to-date object that is or will be > committed to the db at the appropriate time. That is an implicit > contract in the nature of caching an ORM. > > If you insert into that cache manually from some other source, you > completely violate that contract. There is no guarantee that the next > person fetching an object (or collection) will get data that is up-to- > date and will be (or already is) persisted in the database. > > You are bypassing the mechanism which NHibernate tracks what in the > cache needs flushed to the DB, and thus breaking the entire point of > having the cache. > > Why not just fetch and update the object in question with the data you > received from some other source, and the cache (and eventually the db) > will be up to date. Data coming in from some other source should be > treated just like any other disconnected object, and there is tons of > documentation about dealing with this in NHibernate. > > Or am I missing something about your request? > > On Aug 5, 11:18 am, Huge <[email protected]> wrote: > > > > > Thank you, one and all, for the good insight. I'm new to NHibernate > > and I might have dumb questions or perhaps be too wordy. You can say > > whatever you want about me, I also have a thick skin, like Fabio said, > > you will have a very hard time to offend me :) > > > So, please if you could just clarify a little more, that would be > > great. What did you mean by: > > > "the underlying caching system used for l2 caching is the one you can > > add the object to yourself, that's what was meant." > > > Great so it does sound like there's a way to add an object received > > via network connection into the L2 cache, by accessing "the underlying > > system". But in some ways that last statement contradicted your > > previous few which said that was the ORM's job. If you could just > > provide a link or two that might demonstrate how to do add an object > > to that myself, I think that would solve my original need. > > > Thanks again, H > > > On Aug 5, 1:21 am, "Frans Bouma" <[email protected]> wrote: > > > > Apparently no-one else is mature enough to answer this guy's questions, so > > > let me give it a try. > > > > > "The NH cache is for objects retrieved by NH" > > > > > I understand that. What confuses me is that somebody wrote an API to > > > > take > > > > things out of that cache without writing an API to put things into it. > > > > > Why allow the ability to take something out of that cache? Somebody had > > > > justification for writing such a function back in the day. > > > > The caching mechanism is in the o/r mapper, it's FOR the o/r > > > mapper, > > > when it materializes entity class instances with the data from the db. So > > > objects end up in the cache because the o/r mapper decided to do so. > > > > It can be you need to remove an object from the cache, because you > > > removed it from the db using other means, e.g. a trigger, a separate > > > process > > > on another machine, you name it. This way you can, in case of emergency, > > > remove it. I think that's the reason behind this method but we can only > > > guess, we didn't write the method. I agree that it's not a shiny example > > > of > > > proper design, but NHibernate has plenty of that kind of hodgepodge stuff, > > > added during the years, as it's a framework which exists for a long time > > > (and inherited it from the Java version) > > > > > So, isn't that same justification viable for a reason to be able to > > > > stuff > > > > something into that cache? Even better yet a > > > > SessionFactory.Replace(object) would be perfect, because I just need to > > > take > > > > the new copy of Object A and overwrite the old Object A and have that > > > > new > > > > Object A be the master. > > > > that would mean you'd place yourself on the seat of the o/r mapper > > > which decides when to keep objects in the cache. That's not your job, > > > leave > > > that to the o/r mapper. If you want to use a cache for your objects, use > > > ... > > > a cache :) The l2 cache here is out of reach so use another one. > > > > > "If you are getting it from other source, you can cache it yourself > > > > using > > > > the same underlying cache (syscache, memcached, etc)" > > > > > I'm not sure what you mean. Are you saying there is a way to stuff an > > > > object into the L2 cache? If so, how do I get at the SessionFactory's > > > > underlying memory structure that is used to implement that cache? Or, > > > > are > > > > you saying that I should implement my own cache, separate from > > > > SessionFactory? In that case, what good would it do, because > > > SessionFactory > > > > wouldn't be aware that I have a separate cache where it could find > > > > objects > > > > instead of selecting them. > > > > the underlying caching system used for l2 caching is the one you > > > can > > > add the object to yourself, that's what was meant. > > > > FB > > > > > Thanks for your help. > > > > Hugh > > > > > -- > > > > 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. -- 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.
