spring cloud spring-hystrix 缓存

Posted zfzf1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring cloud spring-hystrix 缓存相关的知识,希望对你有一定的参考价值。

@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 缓存的主要内容,如果未能解决你的问题,请参考以下文章

spring-cloud-config-server

Spring Cloud实战Spring Cloud GateWay服务网关

spring-cloud-config——Quick Start

Spring Cloud入门 - Spring Cloud保护机制

spring cloud 与 spring boot 和 spring cloud alibab 版本号对应

整合spring cloud云服务架构 - Spring Cloud简介