目前我正在使用EhCache来存储和检索记录。我已经在缓存中插入了一些元素值作为键值对。现在我的要求是通过匹配该缓存中的键来使用查询来获取值。我的代码如下:
public static void getResultsUsingQuery() throws Exception {
try {
Configuration cacheManagerConfig = new Configuration();
CacheConfiguration cacheConfig = new CacheConfiguration("C5", 0).eternal(true);
Searchable searchable = new Searchable();
cacheConfig.addSearchable(searchable);
CacheManager cacheManager = new CacheManager(cacheManagerConfig);
cacheManager.addCache(new Cache(cacheConfig));
Cache c4 = cacheManager.getCache("C5");
Results results = c4.createQuery().addCriteria(Query.KEY.eq("Label_1")).includeKeys().execute();
//Results results = c4.createQuery().addCriteria(Query.KEY.eq("C5_1")).includeValues().execute();
for (Result result : results.all()) {
System.out.println("" + result.getKey());
}
System.out.println(results.size());
} catch (Exception ex) {
System.out.println("Error While Executing Query");
}
}
执行此程序时,我无法检索记录。我不知道我在程序中做错了什么。帮我看看结果。
Note : My cache name is "C5" and I have inserted the values as key pair like ["Label_1", "C5_1"],.....["Label_10","C5_10"]... Now I want to get the results as C5_1.. So I need to use the query like equating the key with "Label_1".