how to configure second level cache in code (not thru xml)
the current settings i have are:
public NHCachingSetup(Configuration cfg)
{
// use first level cache
cfg.Cache(x =>
{
x.UseQueryCache = true;
x.Provider<SysCacheProvider>();
});
// set 60 min expiration time
cfg.SessionFactory().Caching
.WithDefaultExpiration(60);
}
The way I have done this with NH 3.3 is like
var configure = new Configuration();
...
configure.Cache(x => x.UseQueryCache = true)
...
configure.SessionFactory().Caching
.Through<SysCacheProvider>().WithDefaultExpiration(1440);//secs!
edit in your mapping you will need:-
Cache(x => x.Usage(CacheUsage.ReadOnly));
end edit
Then to use you can do something like (this caches a lookup table for me):-
Db.Query<SpamAssassin>().Cacheable().CacheMode(CacheMode.Normal).ToList();