NHibernate is an open source Object-Relational Mapping solution which provides a framework for mapping relational database on object oriented representation of data. This reduces significant developer's efforts for retrieving data from database. Furthermore to improve applications performance and reduce load on database, NHibernate provides feature of caching to reduce repetitive database calls.
NHibernate First Level Cache
NHibernate First level caching module provides session level in process caching. Whenever a session is created, a session cache is associated with it. When an object is loaded from the database, a copy of object is maintained in the session cache. If the object is to be fetched again in the same session, cached copy of object is returned. In a particular transaction, if the same object is updated multiple times, it is only updated in session cache. At committing transaction, only the final state of object is persisted in database, thus avoiding repetitive update calls.
NCache as NHibernate Second Level Cache
NCache provides NHibernate second level cache provider. NCache provider can be configured as NHibernate second level cache without any code change. Using NCache as second level cache for NHibernate enable application to use NCache's distributed caching features.
NCache provides the following features with second level cache provider:
-
Database Dependencies: To ensure data consistency with database, NCache provides database dependency feature for NHibernate applications that can be configured on entity bases. Database dependency synchronizes cache data with the database such that any change in database record invalidates respective entity in cache. Thus NHibernate retrieves up to date record even if database is updated by an application other than NHibernate application.
See Also