Just a line item on the recording technique used under ......
EhCache is a pure Java caching framework of the process, with fast, lean, etc., Hibernate is the default CacheProvider.
Ehcache features
(1) quick and simple, with a variety of caching policy
(2) There are two levels to the data cache memory and disk, cache data is written to disk in the process of restarting a virtual machine
(3) via RMI, etc. can be inserted into the distributed API caches
(4) the listening socket having a cache and a cache manager
(5) Cache Manager supports multiple instances, and one example of a plurality of cache area. Hibernate and provides a cache implementation
The project involves a packet protocol conversion, to use all kinds of api or message format template needs to cache memory in order to reduce the time-consuming conversion messages, select Ehcache is more suitable, fast, simple
Ado, take a little demo
A, Springboot integrate Ehcache
- Configuration dependency
pom.xml dependency added ehcache
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
2. Configure ehcache.xml
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
<!-- Disk storage: the objects in the cache temporarily not in use, transfer to the hard disk, similar to the Windows system virtual memory path: Specifies objects stored on the hard disk path You can configure directory path are: user.home (the user's home directory) user.dir (user's current working directory) java.io.tmpdir (default temporary directory) ehcache.disk.store.dir ( Ehcache configuration directory) Absolute path (eg: D: \\ Ehcache) View path method: String tmpDir = System.getProperty ( "java.io.tmpdir"); --> <diskStore path="java.io.tmpdir" /> <!-- eternal: the content is permanently stored in the cache memory; when the value is set to true, and the two values timeToIdleSeconds timeToLiveSeconds properties would be ineffective maxElementsInMemory: an upper limit on the cache, how many records the object store up timeToIdleSeconds: After the cache is created, the time interval when the date of the last visit to the cache of failure; the default value is 0, that is, idle time can be infinite timeToLiveSeconds: Cache inception interval of time until the expiration date; the default is 0. survival time is infinite objects overflowToDisk: If the data memory exceeds maxElementsInMemory, whether to use disk storage diskPersistent: disk storage entry is stored permanently maxElementsOnDisk: The maximum number of hard disk cache memoryStoreEvictionPolicy: The default policy is LRU (least recently used). You can set FIFO (First In First Out) or LFU (rarely used)
-->
<cache name="usercache" eternal="false" maxElementsInMemory="10000" overflowToDisk="true" diskPersistent="false" maxElementsOnDisk="0" timeToIdleSeconds="0" timeToLiveSeconds="0" memoryStoreEvictionPolicy="LRU" /> </ehcache> |
3. Configure enable ehcache comment
1 @SpringBootApplication 2 @EnableCaching 3 public class App { 4 public static void main(String[] args) { 5 SpringApplication.run(App.class, args); 6 } 7 }
4.