The contents of this section
Introduced
NHibernate Level Cache Introduction
NHibernate Level Cache Management
Conclusion
Introduced
Do you guys have a look at the last article? Object state. This can easily extend to the nhibernate cache. We use the NHibernate caching mechanism flexibly in the project. NHibernate performance will be greatly improved oh, we next to explore the NHibernate caching mechanism, this article I do not prepare anything, first to learn the next NHibernate cache.
NHibernate Level Cache Introduction
NHibernate-level cache, ISession cache, ISession cache is a transaction-level cache and is nhibernate built in. The data in the ISession cache is used only within this isession cycle.
You can use the ISession cache after the ISession instance is created. Thereafter, when the ISession instance operates on the data, the built-in cache is queried first, and the cached data is used directly if the corresponding data exists in the ISession cache. If it does not exist, the database is queried and its results are in the cache.
Example 1: Querying a persistent instance[Test]
public void SessionCacheTest()
{
Customer customer = _transaction.GetCustomerById(1);
}
This is how we normally query a data, NHibernate initialization ISession, the ISession cache does not exist in this data, then nhibernate need to load data from the database.