`
zhushidan100
  • 浏览: 29793 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

ehcache search

 
阅读更多

 

  • 在用ehcache做搜索的时候,cache不能存放于非内存上(缓存初始化失败),至v 2.5.2,ehcache还没有实现非内存搜索,因此在做缓存的时候不能flush,此方法会将缓存写入硬盘,因此会使缓存丢失.
  • CacheManager cachemanager = CacheManager.getInstance();
    		Cache cache = cachemanager.getCache("andCache");
    		Attribute<String> attribute = cache.getSearchAttribute("pilepoint_number");
    		Query query = cache.createQuery();
    		query.includeValues();
    		query.includeAttribute(attribute);
    		query.addCriteria(attribute.ilike("00010*"));
    		
    		long start = System.currentTimeMillis();
    		Results rls = query.execute();
    		System.out.println("search time   : " + (System.currentTimeMillis() - start));
    		
    		System.out.println(rls.size());
    		
    		List<Result> all = rls.all();
    		
    		for (Result result : all) {
    			System.out.println(result.getKey());//此方法对应query.includeKeys();不在查询前设置此方法会抛出异常,结果集包含key,以下类似
    			System.out.println(result.getAttribute(attribute));
    			System.out.println(result.getValue());
    		}
      (补一句,,ehcache 非常快,api挺友好.)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics