【问题标题】:Ehcache stores data in physical storage instead of in-memory storage - grails 2.xEhcache 将数据存储在物理存储而不是内存存储中 - grails 2.x
【发布时间】:2014-04-21 06:15:49
【问题描述】:

我已经浏览了这个博客以使用 grails 中的二级缓存

link

& 我做了以下更改

在 resources.groovy 中

      userCache(
    org.springframework.cache.ehcache.EhCacheFactoryBean) {
  }

内部服务类

    def userCache

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

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

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

我的设置是

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 是

<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"
        />

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

【问题讨论】:

    标签: grails grails-orm ehcache


    【解决方案1】:

    似乎 ehcache.xml 中提供的默认值不适用于 resources.groovy 中提到的 bean,所以我在这里添加了属性来解决这个问题

    userCache(org.springframework.cache.ehcache.EhCacheFactoryBean) { bean ->
               maxElementsInMemory="1000"
               eternal="true"
               overflowToDisk="false"
               memoryStoreEvictionPolicy="LRU"
        }
    

    【讨论】:

      猜你喜欢
      • 2011-11-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2012-05-13
      相关资源
      最近更新 更多