Question

Every second I store a lot of objects Foo but new object is compared to previous.

Can I configure NHibernate Second Level Cache to keep only last Foo object or should I implement this myself?

Little context:
I have object Doo which is cached and have reference LastFoo to object Foo. Doo is cached but Foo not. Maybe this cache can be done only through reference to last Foo?

More background:
When new Foo is created it's obvious that it will be saved in database. I reference to it through LastFoo property. When the next Foo is created I must compare to previous and only that one. I can take it from LastFoo but NHibernate always query for it.

How to avoid db hit for previous Foo (and only this one, I don't want to cache all Foo objects)? Is it even possible using NHibernate or I need to cache it myself?

Was it helpful?

Solution

I decided to add cacheable entity LatestFoo and reference to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top