码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud spring-hystrix 缓存

时间:2018-03-12 21:11:18      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:type   test   key   div   get   tca   move   iat   out   

@Service
public class CacheService {

	@Autowired
	private RestTemplate restTpl;
	
	@CacheResult
	@HystrixCommand
	public Member cacheMember(Integer id) {
		System.out.println("调用 cacheMember 方法");
//		Member member = restTpl.getForObject(
//				"http://spring-hy-member/member/{id}", Member.class, id);
		return null;
	}
	
	@CacheResult
	@HystrixCommand(commandKey = "cacheKey")
	public String getCache(Integer id) {
		System.out.println("执行查询方法");
		return null;
	}
	
	@CacheRemove(commandKey = "cacheKey")
	@HystrixCommand
	public void removeCache(Integer id) {
		System.out.println("删除缓存方法");
	}
}

  

@RestController
public class CacheController {
	
	@Autowired
	private CacheService cacheService;

	@RequestMapping(value = "/cache", method = RequestMethod.GET, 
			produces = MediaType.APPLICATION_JSON_VALUE)
	public String cache() {
		for(int i = 0; i < 3; i++) {
			cacheService.cacheMember(1);
		}
		return "";
	}
	
	@RequestMapping(value = "/rc", method = RequestMethod.GET, 
			produces = MediaType.APPLICATION_JSON_VALUE)
	public String testRemoveCache() {
		cacheService.getCache(1);
		cacheService.getCache(1);
		
		cacheService.removeCache(1);
		System.out.println("#########  分隔线   ###########");
		cacheService.getCache(1);
		return "";
	}
}

  

spring cloud spring-hystrix 缓存

标签:type   test   key   div   get   tca   move   iat   out   

原文地址:https://www.cnblogs.com/zfzf1/p/8550680.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!