Skip to content

Commit 6c6c077

Browse files
committed
ehcache get/put cache
1 parent 994f15d commit 6c6c077

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
<dependency>
296296
<groupId>net.sf.ehcache</groupId>
297297
<artifactId>ehcache</artifactId>
298-
<version>2.10.2.2.21</version>
298+
<version>2.10.4</version>
299299
</dependency>
300300
<dependency>
301301
<groupId>net.sf.ehcache</groupId>

src/main/java/cn/com/ttblog/ssmbootstrap_table/controller/EhcacheController.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import java.util.Arrays;
44

5+
import net.sf.ehcache.Element;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78
import org.springframework.beans.factory.annotation.Autowired;
8-
import org.springframework.context.ApplicationContext;
99
import org.springframework.stereotype.Controller;
1010
import org.springframework.ui.ModelMap;
1111
import org.springframework.web.bind.annotation.PathVariable;
1212
import org.springframework.web.bind.annotation.RequestMapping;
1313
import net.sf.ehcache.Cache;
1414
import net.sf.ehcache.CacheManager;
15+
import org.springframework.web.bind.annotation.ResponseBody;
1516

1617
/**
1718
* 浏览ehcache状态
@@ -24,14 +25,15 @@ public class EhcacheController {
2425
// private ApplicationContext applicationContext;
2526
@Autowired
2627
private CacheManager cacheManager;
28+
2729
@RequestMapping(value = {"/index/{cache}" })
2830
public String index(@PathVariable("cache") String cache, ModelMap m) {
2931
logger.debug("cache:{}", cache);
3032
if(cacheManager!=null){
3133
m.put("caches",Arrays.deepToString(cacheManager.getCacheNames()));
3234
m.put("getDiskStorePath", cacheManager.getDiskStorePath());
3335
m.put("getName", cacheManager.getName());
34-
// m.put("getOriginalConfigurationText", cacheManager.getOriginalConfigurationText());
36+
m.put("getOriginalConfigurationText", cacheManager.getOriginalConfigurationText());
3537
m.put("getStatus", cacheManager.getStatus());
3638
Cache c=cacheManager.getCache(cache);
3739
if(c!=null){
@@ -42,4 +44,33 @@ public String index(@PathVariable("cache") String cache, ModelMap m) {
4244
logger.debug("ehcache model:{}",m);
4345
return "ehcache";
4446
}
47+
48+
/**
49+
* put到指定cache下
50+
* @param cacheName
51+
* @param key
52+
* @param val
53+
* @return
54+
*/
55+
@RequestMapping(value = {"/putcache/{cache}/{key}/{val}" })
56+
@ResponseBody
57+
public Element put(@PathVariable("cache") String cacheName,@PathVariable("key") String key,@PathVariable("val") String val) {
58+
Cache cache=cacheManager.getCache(cacheName);
59+
Element element=new Element(key,val);
60+
cache.put(element);
61+
return element;
62+
}
63+
64+
/**
65+
* 获取指定cache下的指定key内容
66+
* @param cacheName
67+
* @param key
68+
* @return
69+
*/
70+
@RequestMapping(value = {"/getcache/{cache}/{key}" })
71+
@ResponseBody
72+
public Element get(@PathVariable("cache") String cacheName,@PathVariable("key") String key) {
73+
Cache cache=cacheManager.getCache(cacheName);
74+
return cache.get(key);
75+
}
4576
}

src/main/java/cn/com/ttblog/ssmbootstrap_table/listener/TestReceiveLoginEventListener1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Component
1212
public class TestReceiveLoginEventListener1 implements SmartApplicationListener {
1313

14-
private static final Logger log = LoggerFactory.getLogger(TestReceiveLoginEventListener2.class);
14+
private static final Logger log = LoggerFactory.getLogger(TestReceiveLoginEventListener1.class);
1515

1616
@Override
1717
public boolean supportsEventType(final Class<? extends ApplicationEvent> eventType) {

src/main/resources/spring/spring-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<context:component-scan base-package="cn.com.ttblog.ssmbootstrap_table">
1616
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
17+
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
1718
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
1819
</context:component-scan>
1920

src/main/resources/spring/spring-mvc.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<!-- 多包扫描测试 -->
1616
<context:component-scan base-package="cn.com.ttblog.ssmbootstrap_table.controller,com.other.**,org.exampledriven.cxfexample.**" use-default-filters="false">
1717
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
18+
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController" />
1819
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
1920
</context:component-scan>
2021

0 commit comments

Comments
 (0)