TestEhcacheController.java 1.48 KB
package com.yoho.search.restapi.tools;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.model.CacheObject;
import com.yoho.search.service.scene.common.CommonSceneProductListService;

@Controller
public class TestEhcacheController {
	
	@Autowired
	private EhCache ehCache;
	@Autowired
	private CommonSceneProductListService commonSceneProductListService;
	
	@RequestMapping(value = "/testPut")
	@ResponseBody
	public Map<String, Object> testPut(int count,int viewNum) {
		Map<String,String> paramMap = new HashMap<String, String>();
		paramMap.put("viewNum", ""+viewNum);
		JSONObject productList = (JSONObject)commonSceneProductListService.productList(paramMap).getData();
		for (int i=1;i<=count;i++) {
			ehCache.addOrUpdate("Key"+i, new CacheObject(productList), 1);
		}
		System.out.println(ehCache.getStatistics());
		return new HashMap<String, Object>();
	}
	
	@RequestMapping(value = "/testGet")
	@ResponseBody
	public Map<String, Object> testGet(int count) {
		for (int i=1;i<=count;i++) {
			System.out.println("Key"+i+"_"+ehCache.exist("Key"+i));
		}
		System.out.println(ehCache.getStatistics());
		return new HashMap<String, Object>();
	}

}