NHibernate Second Level Cache

Just wondering if the team has looked into utilizing the NHibernate second level cache. I played around with it some today and got it working on the 1.2 release. There were some issues with the unused ContentPartRecord proxies on ContentItemRecord
or ContentItemVersionRecord that I had to put a hacked workaround in for, but overall it seems like it's pretty solid. It makes a big difference on the number of queries...on the "Welcome to Orchard" page with the default recipe, on the second
page load (primed cache) 25 out of the 36 queries are loaded from the 2nd level cache for an authenticated user, and 19 out of 28 queries are loaded for an authenticated user.

Please let me know if you would like me to submit a patch for the work I've done.

Excellent! Louis tells me that yes, they investigated that and hit the same roadblocks that you did, which is why it never went in. The reasoning was that we would move to nHib 3 anyways, where those hacks will be unnecessary. The move to nHib 3 should be
happening very soon but in the dev branch (that means Orchard 2.0).

Nothing known specifically, just a general sense or assumption that figuring out a workaround
before making the NH2-3 jump would be adding another twist that wouldn't hop up cleanly. (The contentitem/part record relationship is already a sticking point in the upgrade.)

That said, since you've figured out how to make it work, thanks! That seems like a great thing to have if any 1.x sites want to retrofit that in.

Since it sounds like the team isn't planning on integrating this in 1.x, I packaged this up into a module for people to try out. I'm not putting it into the gallery because there are a couple big caveats: 1) It hasn't been fully tested, and 2) I can
almost guarantee that it will blow things up when anyone tries to upgrade to v2. It should be easy to remove, it doesn't create anything persistent, it just overrides a couple of the core NHibernate config services. Let me know if anyone tries
it out.

Louis - I also was able to get the query cache working locally. In my previous experience, I had trouble with it being smart enough to know when to flush the cache for a specific query, however I think the rigid structure of orchard helped
it to work perfectly in my testing. This got the queries down to about 5% of the default codebase, and it seemed to be spot on in terms of invalidating queries when needed.

I would love to include this in my module, however I can't for the life of me figure out how to override the DefaultContentQuery. It's registered completely differently than the other dependencies I've found, see
here.

I tried everything I could think of, including creating my own autofac module, but can't for the life of me get orchard to pick up my implementation.

Can you or someone else help me to figure out how to override it? Thanks so much.

If you'd like I'd say feel free to push out an early module with just the caching by entity identity, even without query caching that would be very nice to have.

For the query it might be interesting to see what sort of alterations or information you need - I'm wondering if the default query could have some more event hooks to allow this type of deep participation/alteration between any number of modules?

Honestly, I tossed the code because I couldn't get it to work, but it would be simple enough to do again. But I'm probably not going to spend the time on that unless it's going to able to be used...which brings me back to the question I was asking.
How do I override DefaultContentQuery? I think someone just asked a very similar question here: http://orchard.codeplex.com/discussions/266041