Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been working a a similar situation, where I just want to cache specific elements, and want these elements to be loaded once on start up, and kept in cache, until the application is shut down. This is a read only cache, and is used to populate a list of countries, so that a user can select their country from the list.</p> <p>I used fluentNhibernate Mappings, and defined Country my class with Cache.readonly() </p> <pre><code>public class CountryMap : ClassMap&lt;Country&gt; { public CountryMap() { Schema("Dropdowns"); Cache.ReadOnly(); // Class mappings underneath } } </code></pre> <p>My user class map looks like this:</p> <pre><code>public class UserMap : ClassMap&lt;User&gt; { Id(x =&gt; x.Id).Column("UserId"); Map(x =&gt; x.FirstName); Map(x =&gt; x.LastName); References(x =&gt; x.Country) .Column("CountryId"); } </code></pre> <p>I manually configure Fluent Nhibernate to use Second level cache. So in my fluent Confuguration I have:</p> <pre><code>var sessionFactory = Fluently.Configure() .Database (...) // set up db here .Mappings(...) //set up mapping here .ExposeConfiguration(c =&gt; { // People advice not to use NHibernate.Cache.HashtableCacheProvider for production c.SetProperty("cache.provider_class", "NHibernate.Cache.HashtableCacheProvider"); c.SetProperty("cache.use_second_level_cache", "true"); c.SetProperty("cache.use_query_cache", "true"); }) .BuildSessionFactory(); </code></pre> <p>I have checked in SQL profiler, and when I get a list of countrys for a user, the are loaded once, and I get cache hits after every other request. The nice thing is that when displaying the users country name, it loads from the cache, and does not make a request to the database. I got some tips from this posting by <a href="http://web.archive.org/web/20100918095719/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/09/first-and-second-level-caching-in-nhibernate.aspx?" rel="nofollow noreferrer">Gabriel Schenker</a>. Hope that helps? If you found a better/proper way, please let me know? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload