Configuring the second-level cache with code

NHibernate also provides an option for cache configuration with the NHibernate.Cfg.Loquacious namespace. In this recipe, we'll show you how to configure the second-level cache with code.

Getting ready

Complete the Getting Ready instructions at the beginning of. Chapter, Queries.

How to do it...

  1. Add a reference to NHibernate.Caches.SysCache using NuGet Package Manager Console.
  2. Add a new folder named CachingWithCode to the project.
  3. Add a new class named Recipe to the folder:
    using NH4CookbookHelpers.Queries;
    using NH4CookbookHelpers.Queries.Model;
    using NHibernate;
    using NHibernate.Caches.SysCache;
    using NHibernate.Cfg;
    
    namespace QueryRecipes.CachingWithCode
    {
      public class Recipe : QueryRecipe
      {
      }
    }
  4. In Recipe ...

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.