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



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

链路

&我做了以下更改

在资源中。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-disksstore.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"
        />

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

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

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

最新更新