Hibernate (14) cache and hibernate Cache
1. What is cache?
The cache is between an application and a permanent mandatory data storage source. The purpose is to reduce the frequency of direct read/write of permanent mandatory data storage sources by applications, thus improving the running performance.
The cache is usually in the memory, for example:
Word and excel in Office
Sessions and SessionFactory in Hibernater
II. The Life Cycle of November in JVM
- When the new statement creates a JAVA object, JVM allocates a memory for the current object.
- As long as the current object is referenced by other resources, it will always exist in the memory.
- If the current object is not referenced by other resources, the lifecycle ends.
- If an object is referenced by another object that has not completed its lifecycle, its lifecycle will not end.
Iii. cache Scope
Iv. cache plug-ins
Ehcache. xml
<? Xml version = '1. 0' encoding = 'utf-8'?> <Ehcache> <diskStore path = "java. io. tempdir"/> <! -- MaxElementsInMemory: Total number of records that can be stored in the cache eternal: whether the current cache never expires overflowToDisk: whether to write the cached data to the local hard disk timeToIdleSeconds when the data in the current cache reaches the maximum value: the maximum idle time of the Current cache. If this time is exceeded, the cache timeToLiveSeconds will be destroyed. After the cache is created, when this time is reached, it is automatically destroyed --> <defaultCache maxElementsInMemory = "5" eternal = "false" overflowToDisk = "true" timeToIdleSeconds = "15" timeToLiveSeconds = "120"/> <>
Hibernate. cfg. xml
<? Xml version = '1. 0' encoding = 'utf-8'?> <! DOCTYPE hibernate-configuration PUBLIC "-// Hibernate/Hibernate Configuration DTD 3.0 // EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <! -- Generated by MyEclipse Hibernate Tools. -->
Object Configuration
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Mapping file autogenerated by MyEclipse Persistence Tools-->