首页>代码>springside的showcase>/showcase/src/main/java/org/springside/examples/showcase/demos/cache/ehcache/EhcacheDemo.java
package org.springside.examples.showcase.demos.cache.ehcache;

import static org.junit.Assert.*;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springside.modules.test.spring.SpringContextTestCase;

/**
 * 演示Ehcache的配置.
 * 
 * 配置见applicationContext-ehcache.xml与ehcache.xml
 * 
 * @author calvin
 */
@ContextConfiguration(locations = { "/cache/applicationContext-ehcache.xml" })
public class EhcacheDemo extends SpringContextTestCase {

	private static final String CACHE_NAME = "demoCache";

	@Autowired
	private CacheManager ehcacheManager;

	private Cache cache;

	@Test
	public void demo() {

		cache = ehcacheManager.getCache(CACHE_NAME);

		String key = "foo";
		String value = "boo";

		put(key, value);
		Object result = get(key);

		assertEquals(value, result);
	}

	public Object get(String key) {
		Element element = cache.get(key);
		return element.getObjectValue();
	}

	public void put(String key, Object value) {
		Element element = new Element(key, value);
		cache.put(element);
	}
}
最近下载更多
bannerwang  LV2 2018年10月30日
wkc  LV21 2018年5月13日
dachoumomo  LV12 2018年2月2日
yhlcrl  LV1 2016年3月10日
微微上翘  LV23 2015年11月30日
zzlsrj  LV10 2015年3月14日
骑着猪猪去逛街  LV32 2013年12月27日
pauldu1104  LV1 2013年7月14日
jaodge  LV1 2013年6月24日
cxw  LV1 2013年5月15日
最近浏览更多
酒瓯224656565 2019年10月14日
暂无贡献等级
shuiyizq  LV5 2019年7月30日
chengqiang  LV13 2019年5月28日
bannerwang  LV2 2018年10月30日
wkc  LV21 2018年5月13日
dachoumomo  LV12 2018年2月2日
zyl  LV34 2017年10月23日
sdomysky1234  LV6 2017年2月28日
xianggang  LV1 2017年1月8日
danelumax 2016年12月20日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友