I am using Spring 3.2.2.RELEASE with Ehcache v.2.7.0
我想在缓存上执行可搜索的操作,我知道手动方式如下所示,我可以使用@Cacheable上的注释轻松实现它
public List<SourceLite> searchInSourceLite(String searchText){
Query query = sourceCache.createQuery();
query.includeKeys();
query.includeValues();
Attribute<String> fullNameAttrib = sourceCache.getSearchAttribute("fullName");
query.addCriteria(fullNameAttrib.ilike("*"+searchText+"*"));
Results results = query.execute();
List<Result> records = results.all();
System.out.println(records.size());
return new ArrayList<SourceLite>(0);
}
- Ehcache xml文件条目
<cache name="sourceLiteCache"
maxEntriesLocalHeap="50000"
eternal="false"
timeToLiveSeconds="10800"
memoryStoreEvictionPolicy="LFU">
<searchable>
<searchAttribute name="fullName" expression="value.getFullName()" />
<searchAttribute name="id" expression="value.getId()" />
</searchable>
</cache>
- Java源类
@Cacheable(value=CacheNames.SOURCE_LITE_CACHE)
@Override
public List<SourceLite> getAllSourceLite() {
return sourceDao.getAllSourceLites();
}