TestEhcacheController.java
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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>();
}
}