Hibernate data Cache

Source: Internet
Author: User

In hibernate, the cache will work in the following scenarios:
1. When loading data via id[primary key]
2. Lazy Loading

First-level caching:
Also known as the internal cache, the data object associated with the current session is saved, which is created with the creation of the session instance and dies out. This is called the session level cache.

The first-level cache is normally hibernate and automatically maintained, and if manual intervention is required, it can be done in the following ways.
1.session.evict
Clears a particular object from the internal cache.
2.sessin.clear
Empty the internal cache

Second-level cache:
Also known as sessionfactory level Cache.
Use level two caching for what kind of data.
Caching all data is the simplest and most common approach.
However, in some cases, it can affect performance, such as the telephone fee query system, if the cache is implemented, memory will be almost impossible to reuse the data flooding, resulting in performance degradation.
If your data meets the following criteria, you can include it in cache management:
1. The data will not be modified by third party applications.
2.data size within acceptable range
3. Low Data Update frequency
4. The same data may be frequently referenced by the system
5. Non-critical data
Hibernate itself does not provide a product implementation of level two caching (a simple Hashtable-based cache is provided for debugging) and can be implemented using a third-party cache.
By default, Ehcache is implemented as a level two cache.
EHCache Org.ehcache.hibernate.Provider

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.