This project is read-only.

Release cache in N2?

Topics: Developer Forum
Nov 12, 2008 at 3:55 PM

This topic relate to the following topic, but I got some other question regarding cache. I'll try to do a long story short:
I've got 2 sites: 
  • Site A:  Read only N2 site (without any Edit possibilities).
  • Site B:  N2 site that can both read and edit the content.

In other words Site A and Site B uses the same N2 database but for different purpose. The problem is that when editing the content from Site B it doesn't show on Site A until an IIS reset (or something similar) because everyting is cashed through (what I can guess) NHibernate's use_query_cache. I still want to have the cache and what I want to do is to release the cache in Site A programmatically when something is triggered. First I thought that this probobly was just something I could accomplish with the NHibernate API but I've tried SessionFactory.Evict(), Session.Release() and Session.Clear() and I just end up destroying the session for everyone logged on to Site A. But somehow this works on Site B: when something is saved from Site B everyone logged on to Site B can instantly see the result without being logged out. So something happening when the content is saved on Site B the question is what? I've looked through the code but can't find anything that explians the behaviour, or am I wrong in my assumptions? Do you have any hints? ;o)

Best Regards

Nov 12, 2008 at 11:05 PM
Would it be possible to use sql server cache invalidation? It's probably the easiset way to invalidate cache if you're using sql server 2005.

Also if you could check web.config? Please make sure you're using the SysCacheProvider.

    <database caching="true" cacheProviderClass="NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2" />
Nov 14, 2008 at 11:57 AM
Ah! You pointed me in the right direction. Apparently N2 uses NHibernate.Cache.HashtableCacheProvider per default (quite embarassing for me not to see it). Once adding the NHibernate.Caches.SysCache2.SysCacheProvider things begun to work. Thanx!