com.netflix.hystrix.HystrixRequestCache Java Examples

The following examples show how to use com.netflix.hystrix.HystrixRequestCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BettingServiceTest.java    From hystrix_lab with MIT License 4 votes vote down vote up
/**
 * Test - GetHorsesInRace - Uses Caching
 */
@Test
public void testWithCacheHits() {
	
	HystrixRequestContext context = HystrixRequestContext.initializeContext();
	
	try {
		CommandGetHorsesInRaceWithCaching commandFirst = new CommandGetHorsesInRaceWithCaching(mockService, RACE_1);
		CommandGetHorsesInRaceWithCaching commandSecond = new CommandGetHorsesInRaceWithCaching(mockService, RACE_1);

		commandFirst.execute();
		// this is the first time we've executed this command with
		// the value of "2" so it should not be from cache
		assertFalse(commandFirst.isResponseFromCache());

		verify(mockService).getHorsesInRace(RACE_1);
		verifyNoMoreInteractions(mockService);

		commandSecond.execute();
		// this is the second time we've executed this command with
		// the same value so it should return from cache
		assertTrue(commandSecond.isResponseFromCache());

	} finally {
		context.shutdown();
	}

	// start a new request context
	context = HystrixRequestContext.initializeContext();
	try {
		CommandGetHorsesInRaceWithCaching commandThree = new CommandGetHorsesInRaceWithCaching(mockService, RACE_1);
		commandThree.execute();
		// this is a new request context so this
		// should not come from cache
		assertFalse(commandThree.isResponseFromCache());

		// Flush the cache
		HystrixRequestCache.getInstance(GETTER_KEY, HystrixConcurrencyStrategyDefault.getInstance()).clear(RACE_1);

	} finally {
		context.shutdown();
	}
}
 
Example #2
Source File: FwHystrixCommondFlushCache.java    From fw-spring-cloud with Apache License 2.0 2 votes vote down vote up
/**
 * 清理缓存
 *
 * @param name
 */
private static void flushCache(String name) {
    HystrixRequestCache.getInstance(TEST_KEY,
            HystrixConcurrencyStrategyDefault.getInstance()).clear(name);
}
 
Example #3
Source File: CommandUsingRequestCacheInvalidation.java    From tools-journey with Apache License 2.0 2 votes vote down vote up
/**
 * Allow the cache to be flushed for this object.
 * 
 * @param id
 *            argument that would normally be passed to the command
 */
public static void flushCache(int id) {
    HystrixRequestCache.getInstance(GETTER_KEY,
            HystrixConcurrencyStrategyDefault.getInstance()).clear(String.valueOf(id));
}