可搜索的Ehcache索引 - 有哪些选择?

时间:2012-05-10 11:00:45

标签: indexing ehcache

Ehcache的2.5.x documentation表明其标准实现提供了缓存搜索功能,而不依赖于索引并设法产生良好的性能(对于高达1M的元素的缓存,<1s)。实验证实了这一说法。但是,这确实会降低(通过O(N))较大的缓存。

该文档进一步指出,通过使用分布式缓存实现(“由Terracotta服务器阵列支持”),可以获得索引的好处。但是,似乎没有一个解决方案可以解决超过1M个元素的小型缓存,这些元素足够小,不需要分发(我们的1.2M元素适合~1Gb缓存)。

有没有人找到一个解决方法/解决方案来为这种情况提供索引,或者这是否需要大量分发缓存的大锤?

关于这个索引功能是否需要商业Terracotta许可证还有点不清楚(我的印象是Terracotta部分产品是免费提供的,虽然显然没有支持?)

1 个答案:

答案 0 :(得分:1)

我认为EhCache索引功能与Terracotta无关。它是EhCache的核心功能。我正在使用商业版Terracotta支持的Ehcache和Ehcache。

当您提供ehcache.xml配置时,您必须指定哪些字段是可搜索的(每次在缓存中缓存或更新/删除新对象时,这将触发Lucene的索引活动)

以下是此类配置的示例示例(我根据您的要求设置了maxBytesLocalHeap =“1024m”):

<?xml version="1.0" encoding="UTF-8"?>
<ehcache maxBytesLocalHeap="1024m">
 <sizeOfPolicy maxDepth="2000" />
 <defaultCache eternal="false" timeToLiveSeconds="600"/>
 <cache name="myCacheablePOJO" eternal="true" statistics="true">
  <searchable>
   <searchAttribute name="field1" />
   <searchAttribute name="field2" />
   <searchAttribute name="field3" />
  </searchable>
 </cache>
</ehcache>

当你使用基于Terracotta的EhCache API实现时,你必须在类路径上有额外的jar并在配置中启用赤陶:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache maxBytesLocalHeap="1.3g">
 <sizeOfPolicy maxDepth="2000" />
 <defaultCache eternal="false" timeToLiveSeconds="600">
  <terracotta/>
 </defaultCache>
 <cache name="myCacheablePOJO" eternal="true" statistics="true">
  <searchable>
   <searchAttribute name="field1" />
   <searchAttribute name="field2" />
   <searchAttribute name="field3" />
   </searchable>
   <terracotta compressionEnabled="true" />
 </cache>
</ehcache>

请注意,我已将“terracotta”标签添加到缓存名称=“myCacheablePOJO”,并带有可选属性以在缓存中启用对象压缩(以较低的性能成本保存ram空间)。

因此,换句话说,如果没有Terracotta聚类,你的本地EhCache中的1.2M元素就可以了。 您应该考虑的唯一问题是故障转移。您应该问自己以下问题:

  • 我的系统缓存策略是什么?
  • 如果JVM崩溃,系统可以提供丢失的缓存数据吗?
  • 如果JVM重启,如何在本地缓存中填充数据?
相关问题