Search in sources :

Example 11 with ConcurrentMapCache

use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.

the class CachingResourceResolverTests method setup.

@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()));
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 12 with ConcurrentMapCache

use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.

the class GzipResourceResolverTests method setup.

@Before
public void setup() {
    Cache 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<>();
    resolvers.add(new CachingResourceResolver(cache));
    resolvers.add(new GzipResourceResolver());
    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()));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Before(org.junit.Before)

Example 13 with ConcurrentMapCache

use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.

the class AbstractJCacheTests method createSimpleCacheManager.

protected 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;
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) ArrayList(java.util.ArrayList) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Cache(org.springframework.cache.Cache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache)

Example 14 with ConcurrentMapCache

use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.

the class TransactionAwareCacheDecoratorTests method evictTransactional.

@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));
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) DefaultTransactionAttribute(org.springframework.transaction.interceptor.DefaultTransactionAttribute) TransactionStatus(org.springframework.transaction.TransactionStatus) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Example 15 with ConcurrentMapCache

use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.

the class TransactionAwareCacheDecoratorTests method clearTransactional.

@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));
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) DefaultTransactionAttribute(org.springframework.transaction.interceptor.DefaultTransactionAttribute) TransactionStatus(org.springframework.transaction.TransactionStatus) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Aggregations

ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)16 Cache (org.springframework.cache.Cache)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 TransactionStatus (org.springframework.transaction.TransactionStatus)3 DefaultTransactionAttribute (org.springframework.transaction.interceptor.DefaultTransactionAttribute)3 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)2 AnnotatedElementKey (org.springframework.context.expression.AnnotatedElementKey)1 EvaluationContext (org.springframework.expression.EvaluationContext)1