首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ehcache将数据存储在物理存储中,而不是内存中存储- grails 2.x

Ehcache将数据存储在物理存储中,而不是内存中存储- grails 2.x
EN

Stack Overflow用户
提问于 2014-04-21 14:15:50
回答 1查看 593关注 0票数 0

我在这个博客中使用了grails中的二级缓存。

link

我做了以下更改(&I)

在resources.groovy中

代码语言:javascript
复制
      userCache(
    org.springframework.cache.ehcache.EhCacheFactoryBean) {
  }

内部服务类

代码语言:javascript
复制
    def userCache

public def userCachedList(){
    if (userCache.get("userList")) {
        ...
    }
    else {
        ...

        userCache.put(
                new net.sf.ehcache.Element("userList",
                list)
                )
    }
...
}

缓存工作正常,但问题是这个缓存列表存储在物理位置。当我启动应用程序时,我看到在tmp目录中创建了.ehcache-diskstore.lock。

我的设置是

代码语言:javascript
复制
hibernate {
    cache.use_second_level_cache = false
    cache.use_query_cache = false
    //cache.use_structured_entities = false
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
    hibernate.format_sql=false
    hibernate.connection.release_mode='after_transaction'
}

ehcache.xml是

代码语言:javascript
复制
<ehcache name="myapp">

<!-- Necessary for spring-security-acl plugin-->
<!--<diskStore path="java.io.tmpdir"/>-->

<defaultCache
    maxElementsInMemory="20000"
    eternal="false"
    timeToIdleSeconds="3600"
    timeToLiveSeconds="3600"
    overflowToDisk="false">
    <!-- <cacheEventListenerFactory
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/> -->
 </defaultCache>

 <cache 
    name="owsoo.User"
    maxEntriesLocalHeap="50"
    eternal="false"
    timeToLiveSeconds="600"
    overflowToDisk="false">
    <!-- <cacheEventListenerFactory 
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/> -->
 </cache>

<cache name="aclCache"
       maxElementsInMemory="100000"
       eternal="true"
       overflowToDisk="false"
       memoryStoreEvictionPolicy="LRU"
       statistics="true"
        />

要使用内存缓存而不是物理磁盘存储,需要在设置中进行哪些更改?

EN

回答 1

Stack Overflow用户

发布于 2014-04-21 15:52:26

对于resources.groovy中提到的bean,ehcache.xml中提供的缺省值似乎不起作用,因此我在此处添加了属性来解决此问题

代码语言:javascript
复制
userCache(org.springframework.cache.ehcache.EhCacheFactoryBean) { bean ->
           maxElementsInMemory="1000"
           eternal="true"
           overflowToDisk="false"
           memoryStoreEvictionPolicy="LRU"
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23191917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档