【发布时间】:2020-04-03 09:29:47
【问题描述】:
在早期版本的 Ehcache 中,您可以定义默认缓存配置,该配置将应用于以编程方式创建的缓存。自 Ehcache3 以来,他们对配置 xsd 进行了很多更改,似乎不再有与 defaultCache 等效的东西了——或者至少,我在任何地方都找不到它。
例如旧配置:
<ehcache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false">
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="120"
overflowToDisk="false" />
</ehcache>
我尝试了以下配置,但我不知道这是否有效,或者我是否可以删除并忽略它。我想我可以忽略它,因为当我启动应用程序时,我没有收到任何警告说 ehcache 找不到特定缓存的配置。
新配置:
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">
<cache alias="default">
<expiry>
<ttl>120</ttl>
</expiry>
<heap>10000</heap>
</cache>
</config>
我之所以使用alias="default" 是因为在本文档中:ehcache.xml 他们提到 defaultCache 的内部名称是“default”。引用:
Default Cache configuration. These settings will be applied to caches created programmatically using CacheManager.add(String cacheName). This element is optional, and using CacheManager.add(String cacheName) when its not present will throw CacheException The defaultCache has an implicit name "default" which is a reserved cache name.
所以问题是,Ehcache3 中是否有 defaultCache 的等价物,或者我可以直接删除它吗?
【问题讨论】: