类org.springframework.cache.jcache.support.TestableCacheKeyGenerator源码实例Demo

下面列出了怎么用org.springframework.cache.jcache.support.TestableCacheKeyGenerator的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
public void customKeyGenerator() {
	CacheResultOperation operation =
			getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
	assertEquals(defaultCacheResolver, operation.getCacheResolver());
	assertNull(operation.getExceptionCacheResolver());
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGeneratorSpringBean() {
	TestableCacheKeyGenerator bean = new TestableCacheKeyGenerator();
	beanFactory.registerSingleton("fooBar", bean);
	CacheResultOperation operation =
			getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
	assertEquals(defaultCacheResolver, operation.getCacheResolver());
	assertNull(operation.getExceptionCacheResolver());
	KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) operation.getKeyGenerator();
	assertSame(bean, adapter.getTarget()); // take bean from context
}
 
@Test
public void customKeyGeneratorAndCacheResolver() {
	CacheResultOperation operation = getCacheOperation(CacheResultOperation.class,
			CustomServiceWithDefaults.class, name.getMethodName(), Long.class);
	assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
	assertJCacheResolver(operation.getExceptionCacheResolver(), null);
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGeneratorAndCacheResolverWithExceptionName() {
	CacheResultOperation operation = getCacheOperation(CacheResultOperation.class,
			CustomServiceWithDefaults.class, name.getMethodName(), Long.class);
	assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
	assertJCacheResolver(operation.getExceptionCacheResolver(), TestableCacheResolver.class);
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGenerator() {
	CacheResultOperation operation =
			getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
	assertEquals(defaultCacheResolver, operation.getCacheResolver());
	assertNull(operation.getExceptionCacheResolver());
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGeneratorSpringBean() {
	TestableCacheKeyGenerator bean = new TestableCacheKeyGenerator();
	beanFactory.registerSingleton("fooBar", bean);
	CacheResultOperation operation =
			getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
	assertEquals(defaultCacheResolver, operation.getCacheResolver());
	assertNull(operation.getExceptionCacheResolver());
	KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) operation.getKeyGenerator();
	assertSame(bean, adapter.getTarget()); // take bean from context
}
 
@Test
public void customKeyGeneratorAndCacheResolver() {
	CacheResultOperation operation = getCacheOperation(CacheResultOperation.class,
			CustomServiceWithDefaults.class, name.getMethodName(), Long.class);
	assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
	assertJCacheResolver(operation.getExceptionCacheResolver(), null);
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGeneratorAndCacheResolverWithExceptionName() {
	CacheResultOperation operation = getCacheOperation(CacheResultOperation.class,
			CustomServiceWithDefaults.class, name.getMethodName(), Long.class);
	assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
	assertJCacheResolver(operation.getExceptionCacheResolver(), TestableCacheResolver.class);
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGenerator() {
	CacheResultOperation operation =
			getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
	assertEquals(defaultCacheResolver, operation.getCacheResolver());
	assertNull(operation.getExceptionCacheResolver());
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGeneratorSpringBean() {
	TestableCacheKeyGenerator bean = new TestableCacheKeyGenerator();
	beanFactory.registerSingleton("fooBar", bean);
	CacheResultOperation operation =
			getCacheOperation(CacheResultOperation.class, CustomService.class, name.getMethodName(), Long.class);
	assertEquals(defaultCacheResolver, operation.getCacheResolver());
	assertNull(operation.getExceptionCacheResolver());
	KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) operation.getKeyGenerator();
	assertSame(bean, adapter.getTarget()); // take bean from context
}
 
@Test
public void customKeyGeneratorAndCacheResolver() {
	CacheResultOperation operation = getCacheOperation(CacheResultOperation.class,
			CustomServiceWithDefaults.class, name.getMethodName(), Long.class);
	assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
	assertJCacheResolver(operation.getExceptionCacheResolver(), null);
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@Test
public void customKeyGeneratorAndCacheResolverWithExceptionName() {
	CacheResultOperation operation = getCacheOperation(CacheResultOperation.class,
			CustomServiceWithDefaults.class, name.getMethodName(), Long.class);
	assertJCacheResolver(operation.getCacheResolver(), TestableCacheResolver.class);
	assertJCacheResolver(operation.getExceptionCacheResolver(), TestableCacheResolver.class);
	assertCacheKeyGenerator(operation.getKeyGenerator(), TestableCacheKeyGenerator.class);
}
 
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Object customKeyGenerator(Long id) {
	return null;
}
 
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Object customKeyGeneratorSpringBean(Long id) {
	return null;
}
 
@Override
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Long cacheWithCustomKeyGenerator(String id, String anotherId) {
	return counter.getAndIncrement();
}
 
@Override
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Long cacheWithCustomKeyGenerator(String id, String anotherId) {
	return counter.getAndIncrement();
}
 
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Object customKeyGenerator(Long id) {
	return null;
}
 
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Object customKeyGeneratorSpringBean(Long id) {
	return null;
}
 
@Override
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Long cacheWithCustomKeyGenerator(String id, String anotherId) {
	return counter.getAndIncrement();
}
 
@Override
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Long cacheWithCustomKeyGenerator(String id, String anotherId) {
	return counter.getAndIncrement();
}
 
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Object customKeyGenerator(Long id) {
	return null;
}
 
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Object customKeyGeneratorSpringBean(Long id) {
	return null;
}
 
@Override
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Long cacheWithCustomKeyGenerator(String id, String anotherId) {
	return counter.getAndIncrement();
}
 
@Override
@CacheResult(cacheKeyGenerator = TestableCacheKeyGenerator.class)
public Long cacheWithCustomKeyGenerator(String id, String anotherId) {
	return counter.getAndIncrement();
}
 
 类方法
 同包方法