简体   繁体   English

ehcache-永久缓存

[英]ehcache - permanent caching

I am beginner to Ehcache. 我是Ehcache的初学者。

I am trying to do cache SQL query result via mybatis xml and ehcache is caching the query with its result, but it clears the cached data once the operation gets completed even the same JVM instance is running. 我正在尝试通过mybatis xml来缓存SQL查询结果,而ehcache会将其结果缓存在查询中,但是一旦操作完成,即使相同的JVM实例正在运行,也会清除缓存的数据。

Can anyone advise how to store the cache either in disk/memory till JVM termiates? 谁能建议在JVM终止之前如何在磁盘/内存中存储缓存?

Code snippet of mybatis-mapper.xml mybatis-mapper.xml代码段

<cache type="org.mybatis.caches.ehcache.EhcacheCache">
    <property name="eternal" value="false" />
    <property name="maxElementsInMemory" value="100000" />
    <property name="timeToIdleSeconds" value="3600" />
    <property name="timeToLiveSeconds" value="3600" />
    <property name="memoryStoreEvictionPolicy" value="LFU" />
    <property name="statistics" value="true" />
</cache>

..... .....

您正在寻找的是Ehcache Persistence

Not a specialist of the MyBatis - Ehcache bridge. 不是MyBatis-Ehcache桥的专家。 But from your configuration sample, assuming you never want expiry, do the following changes: 但是从您的配置示例中,假设您永远不希望到期,请进行以下更改:

  • eternal property to be set to true eternal属性设置为true
  • Remove the two timeToXXX properties 删除两个timeToXXX属性

This will make sure expiry never gets triggered. 这将确保过期不会触发。 Note though that a cache can still evict to control resource consumption. 请注意,尽管如此,高速缓存仍然可以退出以控制资源消耗。

In order to fixing this issue, we need to explicitly mention the below attributes in the your mapper.xml 1) useCache="true" and flushCache="false" for select operation 2) flushCache="false" for all your insert/update/delete operation 为了解决此问题,我们需要在mapper.xml中明确提及以下属性:1)selectCache操作的useCache =“ true”和flushCache =“ false” 2)所有插入/更新的flushCache =“ false” /删除操作

Sample code snippets:- 示例代码段:-

<select id="getTestData" parameterType="map" resultMap="testDtls"  useCache="true" flushCache="false" >

<insert id="insertTestData" parameterType="map" flushCache="false" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM