org.springframework.cache.concurrent.ConcurrentMapCache Java Examples

The following examples show how to use org.springframework.cache.concurrent.ConcurrentMapCache. 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: TransactionAwareCacheDecoratorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void evictTransactional() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);
	Object key = new Object();
	cache.put(key, "123");


	TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
			TransactionDefinition.PROPAGATION_REQUIRED));
	cache.evict(key);
	assertEquals("123", target.get(key, String.class));
	txManager.commit(status);

	assertNull(target.get(key));
}
 
Example #2
Source File: ResourceHandlerRegistryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resourceChain() throws Exception {
	ResourceUrlProvider resourceUrlProvider = Mockito.mock(ResourceUrlProvider.class);
	this.registry.setResourceUrlProvider(resourceUrlProvider);
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformerSupport mockTransformer = Mockito.mock(ResourceTransformerSupport.class);

	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceWebHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
	Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider);
}
 
Example #3
Source File: EncodedResourceResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setup() {
	Cache cache = new ConcurrentMapCache("resourceCache");

	VersionResourceResolver versionResolver = new VersionResourceResolver();
	versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(cache));
	resolvers.add(new EncodedResourceResolver());
	resolvers.add(versionResolver);
	resolvers.add(new PathResourceResolver());
	this.resolver = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
	this.locations.add(new ClassPathResource("testalternatepath/", getClass()));
}
 
Example #4
Source File: GzipResourceResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	this.cache = new ConcurrentMapCache("resourceCache");

	Map<String, VersionStrategy> versionStrategyMap = new HashMap<>();
	versionStrategyMap.put("/**", new ContentVersionStrategy());
	VersionResourceResolver versionResolver = new VersionResourceResolver();
	versionResolver.setStrategyMap(versionStrategyMap);

	List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>();
	resolvers.add(new CachingResourceResolver(this.cache));
	resolvers.add(new GzipResourceResolver());
	resolvers.add(versionResolver);
	resolvers.add(new PathResourceResolver());
	resolver = new DefaultResourceResolverChain(resolvers);
	locations = new ArrayList<Resource>();
	locations.add(new ClassPathResource("test/", getClass()));
	locations.add(new ClassPathResource("testalternatepath/", getClass()));
}
 
Example #5
Source File: EncodedResourceResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setup() {
	this.cache = new ConcurrentMapCache("resourceCache");

	VersionResourceResolver versionResolver = new VersionResourceResolver();
	versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(this.cache));
	resolvers.add(new EncodedResourceResolver());
	resolvers.add(versionResolver);
	resolvers.add(new PathResourceResolver());
	this.resolver = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
	this.locations.add(new ClassPathResource("testalternatepath/", getClass()));
}
 
Example #6
Source File: ResourceHandlerRegistryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void resourceChain() throws Exception {
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
}
 
Example #7
Source File: ResourceHandlerRegistryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resourceChain() throws Exception {
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
}
 
Example #8
Source File: TransactionAwareCacheDecoratorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void clearTransactional() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);
	Object key = new Object();
	cache.put(key, "123");


	TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
			TransactionDefinition.PROPAGATION_REQUIRED));
	cache.clear();
	assertEquals("123", target.get(key, String.class));
	txManager.commit(status);

	assertNull(target.get(key));
}
 
Example #9
Source File: TransactionAwareCacheDecoratorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void clearTransactional() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);
	Object key = new Object();
	cache.put(key, "123");


	TransactionStatus status = this.txManager.getTransaction(
			new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
	cache.clear();
	assertEquals("123", target.get(key, String.class));
	this.txManager.commit(status);

	assertNull(target.get(key));
}
 
Example #10
Source File: TransactionAwareCacheDecoratorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void evictTransactional() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);
	Object key = new Object();
	cache.put(key, "123");


	TransactionStatus status = this.txManager.getTransaction(
			new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
	cache.evict(key);
	assertEquals("123", target.get(key, String.class));
	this.txManager.commit(status);

	assertNull(target.get(key));
}
 
Example #11
Source File: TransactionAwareCacheDecoratorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void clearTransactional() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);
	Object key = new Object();
	cache.put(key, "123");


	TransactionStatus status = this.txManager.getTransaction(
			new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
	cache.clear();
	assertEquals("123", target.get(key, String.class));
	this.txManager.commit(status);

	assertNull(target.get(key));
}
 
Example #12
Source File: ResourceHandlerRegistryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resourceChain() throws Exception {
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
}
 
Example #13
Source File: EncodedResourceResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() {
	this.cache = new ConcurrentMapCache("resourceCache");

	VersionResourceResolver versionResolver = new VersionResourceResolver();
	versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(this.cache));
	resolvers.add(new EncodedResourceResolver());
	resolvers.add(versionResolver);
	resolvers.add(new PathResourceResolver());
	this.resolver = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
	this.locations.add(new ClassPathResource("testalternatepath/", getClass()));
}
 
Example #14
Source File: ResourceHandlerRegistryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resourceChain() throws Exception {
	ResourceUrlProvider resourceUrlProvider = Mockito.mock(ResourceUrlProvider.class);
	this.registry.setResourceUrlProvider(resourceUrlProvider);
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformerSupport mockTransformer = Mockito.mock(ResourceTransformerSupport.class);
	
	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceWebHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
	Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider);
}
 
Example #15
Source File: EncodedResourceResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() {
	Cache cache = new ConcurrentMapCache("resourceCache");

	VersionResourceResolver versionResolver = new VersionResourceResolver();
	versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(cache));
	resolvers.add(new EncodedResourceResolver());
	resolvers.add(versionResolver);
	resolvers.add(new PathResourceResolver());
	this.resolver = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
	this.locations.add(new ClassPathResource("testalternatepath/", getClass()));
}
 
Example #16
Source File: ExpressionEvaluatorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testMultipleCachingEval() {
	AnnotatedClass target = new AnnotatedClass();
	Method method = ReflectionUtils.findMethod(
			AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
	Object[] args = new Object[] {new Object(), new Object()};
	Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));

	EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args,
			target, target.getClass(), method, CacheOperationExpressionEvaluator.NO_RESULT, null);
	Collection<CacheOperation> ops = getOps("multipleCaching");

	Iterator<CacheOperation> it = ops.iterator();
	AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);

	Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
	Object keyB = this.eval.key(it.next().getKey(), key, evalCtx);

	assertEquals(args[0], keyA);
	assertEquals(args[1], keyB);
}
 
Example #17
Source File: CachingConfiguration.java    From microservices-springboot with MIT License 5 votes vote down vote up
@Bean
@Override
public CacheManager cacheManager() {

    return new ConcurrentMapCacheManager() {

        @Override
        protected Cache createConcurrentMapCache(final String name) {
            return new ConcurrentMapCache(name, CacheBuilder.newBuilder()
                    .expireAfterWrite(30, TimeUnit.MINUTES)
                    .maximumSize(100).build().asMap(), false);
        }
    };
}
 
Example #18
Source File: TransactionAwareCacheDecoratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void putNonTransactional() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);

	Object key = new Object();
	cache.put(key, "123");
	assertEquals("123", target.get(key, String.class));
}
 
Example #19
Source File: CacheConfig.java    From microservices-sample-project with Apache License 2.0 5 votes vote down vote up
public static CacheManager createCacheManager(String... caches) {
List<ConcurrentMapCache> concurrentMapCaches = new ArrayList<>();
for(String cacheName : caches){
	concurrentMapCaches.add(new ConcurrentMapCache(cacheName));
	concurrentMapCaches.add(new ConcurrentMapCache(cacheName + CONCAT + SUFFIX));
}

      SimpleCacheManager cacheManager = new SimpleCacheManager();
      cacheManager.setCaches(concurrentMapCaches);
      return cacheManager;
  }
 
Example #20
Source File: ExpressionEvaluatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private EvaluationContext createEvaluationContext(Object result) {
	AnnotatedClass target = new AnnotatedClass();
	Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class,
			Object.class);
	Object[] args = new Object[] { new Object(), new Object() };
	Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
	EvaluationContext context = eval.createEvaluationContext(caches, method, args, target, target.getClass(), result);
	return context;
}
 
Example #21
Source File: JCacheJavaConfigTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example #22
Source File: EnableTransactionManagementIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager mgr = new SimpleCacheManager();
	ArrayList<Cache> caches = new ArrayList<>();
	caches.add(new ConcurrentMapCache(""));
	mgr.setCaches(caches);
	return mgr;
}
 
Example #23
Source File: CachingResourceResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() {

	this.cache = new ConcurrentMapCache("resourceCache");

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(this.cache));
	resolvers.add(new PathResourceResolver());
	this.chain = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
}
 
Example #24
Source File: ResourcesBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void parseResourceCache(ManagedList<? super Object> resourceResolvers,
		ManagedList<? super Object> resourceTransformers, Element element, Object source) {

	String resourceCache = element.getAttribute("resource-cache");
	if ("true".equals(resourceCache)) {
		ConstructorArgumentValues cavs = new ConstructorArgumentValues();

		RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class);
		cachingResolverDef.setSource(source);
		cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		cachingResolverDef.setConstructorArgumentValues(cavs);

		RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class);
		cachingTransformerDef.setSource(source);
		cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		cachingTransformerDef.setConstructorArgumentValues(cavs);

		String cacheManagerName = element.getAttribute("cache-manager");
		String cacheName = element.getAttribute("cache-name");
		if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) {
			RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName);
			cavs.addIndexedArgumentValue(0, cacheManagerRef);
			cavs.addIndexedArgumentValue(1, cacheName);
		}
		else {
			ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues();
			cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE);
			RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class);
			cacheDef.setSource(source);
			cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			cacheDef.setConstructorArgumentValues(cacheCavs);
			cavs.addIndexedArgumentValue(0, cacheDef);
		}
		resourceResolvers.add(cachingResolverDef);
		resourceTransformers.add(cachingTransformerDef);
	}
}
 
Example #25
Source File: ResourcesBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void parseResourceCache(ManagedList<Object> resourceResolvers,
		ManagedList<Object> resourceTransformers, Element element, @Nullable Object source) {

	String resourceCache = element.getAttribute("resource-cache");
	if ("true".equals(resourceCache)) {
		ConstructorArgumentValues cargs = new ConstructorArgumentValues();

		RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class);
		cachingResolverDef.setSource(source);
		cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		cachingResolverDef.setConstructorArgumentValues(cargs);

		RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class);
		cachingTransformerDef.setSource(source);
		cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		cachingTransformerDef.setConstructorArgumentValues(cargs);

		String cacheManagerName = element.getAttribute("cache-manager");
		String cacheName = element.getAttribute("cache-name");
		if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) {
			RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName);
			cargs.addIndexedArgumentValue(0, cacheManagerRef);
			cargs.addIndexedArgumentValue(1, cacheName);
		}
		else {
			ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues();
			cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE);
			RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class);
			cacheDef.setSource(source);
			cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			cacheDef.setConstructorArgumentValues(cacheCavs);
			cargs.addIndexedArgumentValue(0, cacheDef);
		}
		resourceResolvers.add(cachingResolverDef);
		resourceTransformers.add(cachingTransformerDef);
	}
}
 
Example #26
Source File: CachingResourceResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() {

	this.cache = new ConcurrentMapCache("resourceCache");

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(this.cache));
	resolvers.add(new PathResourceResolver());
	this.chain = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
}
 
Example #27
Source File: CachingResourceResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {

	this.cache = new ConcurrentMapCache("resourceCache");

	List<ResourceResolver> resolvers = new ArrayList<>();
	resolvers.add(new CachingResourceResolver(this.cache));
	resolvers.add(new PathResourceResolver());
	this.chain = new DefaultResourceResolverChain(resolvers);

	this.locations = new ArrayList<>();
	this.locations.add(new ClassPathResource("test/", getClass()));
}
 
Example #28
Source File: TransactionAwareCacheDecoratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void putIfAbsent() { // no transactional support for putIfAbsent
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);

	Object key = new Object();
	assertNull(cache.putIfAbsent(key, "123"));
	assertEquals("123", target.get(key, String.class));
	assertEquals("123", cache.putIfAbsent(key, "456").get());
	assertEquals("123", target.get(key, String.class)); // unchanged
}
 
Example #29
Source File: CacheTestUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a {@link SimpleCacheManager} with the specified cache(s).
 * @param cacheNames the names of the caches to create
 */
public static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example #30
Source File: TransactionAwareCacheDecoratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void regularOperationsOnTarget() {
	Cache target = new ConcurrentMapCache("testCache");
	Cache cache = new TransactionAwareCacheDecorator(target);
	assertEquals(target.getName(), cache.getName());
	assertEquals(target.getNativeCache(), cache.getNativeCache());

	Object key = new Object();
	target.put(key, "123");
	assertEquals("123", cache.get(key).get());
	assertEquals("123", cache.get(key, String.class));

	cache.clear();
	assertNull(target.get(key));
}