1, a first-class cache is session-level cache, session end is the transaction commit, session closed, cache cleanup. Little effect
Get mode: Within a session, the second query does not connect to the database. Applies to first-level caches
Load mode: Lazy load query (do not execute SQL when querying, execute SQL when using result), second query does not connect database. Applies to first-level caches
CreateQuery (HQL). List (): Queries the entire list, and executes SQL the first time a list () is called. on the second query, SQL was executed, stating that the first-level cache is not used. That is, do not use level two cache
createquery (HQL). Iterate (): query only the ID, the first call to iterate (), execute SQL, query ID (query part of the property), when the object is obtained and used, the query entire entity statement appears. However, when the second iterate () executes SQL (does not apply to the first level cache), the query ID (in some fields) does not produce statements when the object is obtained, and the first level cache is applied. Query partial field, return object[] array, do not apply first-level cache. Querying part of a field, encapsulating it as an object
For example, String sql = Select New Userpojo (u.id,u.name) from Userpojo u; the second time the same SQL is executed, and the first level cache is not applied, and the objects that only recognize all fields are cached.
Save: In a session, save is added first, then the Get or load Save method also uses the first level cache
The 2, level two cache is the sessionfactory level cache. Process-level caching, factory-level caching, which can be shared by all sessions. For improved performance
The main is to configure third-party manufacturers. There is a jar package, the cache policy file (Eh.. Cache), configure level two cache vendor classes, turn on level two cache, level two cache properties, configure which classes are eligible for two-level caching, and also require the class's properties (which need to be placed at the bottom of the file), such as read-only.
Secondary cache can be managed and can be emptied by evict
3. Query cache
The query cache stores a partial attribute, also called a normal property
The query cache stores the ID of the entity object
The life cycle of the query cache is indeterminate
Query caching also needs to be configured
List (): In a session, the second query does not execute SQL, indicating that the query cache is applicable. A partial field is queried, and the same applies in two sessions, indicating that the query cache is irrelevant to the session
Hibernate cache, level two cache, query cache