EhCache在java中默认缓存 [英] EhCache default cache in java

查看:383
本文介绍了EhCache在java中默认缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ehCache的配置:

I have this configuration for ehCache:

<ehcache>
    <defaultCache
            name="defaut"
            maxElementsInMemory="5"
            eternal="false"
            timeToIdleSeconds="20"
            timeToLiveSeconds="20"
            overflowToDisk="false"
            diskPersistent="false"
            memoryStoreEvictionPolicy="LRU"
            />           
</ehcache>

如何访问EhCache的默认缓存?

How can I get access to default cache of EhCache?

CacheManager.getInstance().getCache("default"); // returns null


推荐答案

我的理解是默认cache实际上是创建新缓存的模板,而不是特定的命名缓存。

My understanding is that the "default cache" is actually a template for new caches that get created, rather than being a specific named cache.

CacheManager.getCache 只会在已经创建的情况下返回缓存实例,因此您需要告诉它创建一个新的,使用类似 addCacheIfAbsent()。名称无关紧要,它将使用默认缓存设置按需创建。

CacheManager.getCache will only return a cache instance if it has already been created, so you'll need to tell it to create a new one, using something like addCacheIfAbsent(). The name doesn't matter, it will be created on demand using the default cache settings.

这篇关于EhCache在java中默认缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆