NHibernate Tour (23): Explore NHibernate Level two cache (top)

Source: Internet
Author: User

The contents of this section

Introduced

Introduction to NHibernate Level two cache

NHibernate Level Two cache provider

Implement NHibernate Level two cache

Conclusion

Introduced

In the previous article I introduced the NHibernate built-in first-level cache, that is, the ISession cache. Let's take a look at the next NHibernate level two cache, which is the isessionfactory cache. The secondary cache is extensible and provides a third-party NHibernate level two cache provider on the NHibernate contrib.

Introduction to NHibernate Level two cache

The nhibernate level two cache is created by isessionfactory and can be shared by all isession.

In NHibernate, when we enable the NHibernate level two cache. When using ISession for data operations, NHibernate first looks for the existence of the required data from the built-in cache (one level cache), queries the level two cache if there is no required data in the built-in cache, and uses the cached data directly if the required data is present in the level two cache. Otherwise, the data is queried from the database and placed in the cache.

The nhibernate itself provides a Hashtable hashtablecache cache, but with limited functionality and poor performance, which is not suitable for use in large applications, we can use a Third-party cache provider as a nhibernate level two cache implementation.

However, the disadvantage of using caching is that if the cache policy is improperly set, NHibernate does not know that other applications are updating the database in a timely manner. Therefore, it is recommended that you use caching only for read-only data (or data that is rarely modified) that is frequently used by the system, is not large, and is not modified by other applications.

NHibernate Level Two cache provider

NHibernate provides a NHibernate.Cache.ICacheProvider interface for supporting Third-party cache provider implementations. When developing a cache provider, you need to implement the interface as a direct adapter for nhibernate and caching. NHibernate provides built-in adapters for common cache providers that implement the NHibernate.Cache.ICacheProvider interface.

In addition to the Hashtable-based Hashtablecache cache provided by the NHibernate itself, six third-party contrib two-level cache providers are available on NHibernate nhibernate, fully open source. We can use it directly by downloading its assembly references to our project.

NHibernate.Caches.MemCache

NHibernate.Caches.Prevalence

NHibernate.Caches.SharedCache

NHibernate.Caches.SysCache

NHibernate.Caches.SysCache2

NHibernate.Caches.Velocity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.