Domanda

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);
        }
È stato utile?

Soluzione

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();

Altri suggerimenti

got it:

cfg.SetProperty(Environment.BatchSize, "100")
                .SetProperty(Environment.UseQueryCache, "true")
                .SetProperty(Environment.UseSecondLevelCache, "true")
                .Cache(x => { x.Provider<SysCacheProvider>(); });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top