Quantcast
Channel: Fluent NHibernate caching with automapping - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Sergei Tachenov for Fluent NHibernate caching with automapping

$
0
0

I've been struggling with this for a while and was surprised how little information is out there. This question is the best I could find and even here the accepted answer doesn't say how to enable entity caching. Here's what I've found out.

To enable second level cache:

Fluently.Configure()
    .Database(/* your DB config */)
    .Cache(c => c.UseSecondLevelCache().ProviderClass<CacheProviderClass>())

You can use both this and query cache:

Fluently.Configure()
    .Database(/* your DB config */)
    .Cache(c => c.UseSecondLevelCache()
        .UseQueryCache()
        .ProviderClass<CacheProviderClass>())

To enable per-entity caching:

.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>()
              .Conventions.Add(ConventionBuilder.Class.Always(c => c.Cache.ReadWrite()))
          )
)

Of course, you can use ReadOnly() or NonStrictReadWrite() if you wish.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>