Search in sources :

Example 6 with ConcurrentMapCache

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

the class TransactionAwareCacheDecoratorTests method regularOperationsOnTarget.

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

Example 7 with ConcurrentMapCache

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

the class TransactionAwareCacheDecoratorTests method putNonTransactional.

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

Example 8 with ConcurrentMapCache

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

the class ExpressionEvaluatorTests method testMultipleCachingEval.

@Test
public void testMultipleCachingEval() throws Exception {
    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(), 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);
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Method(java.lang.reflect.Method) EvaluationContext(org.springframework.expression.EvaluationContext) AnnotatedElementKey(org.springframework.context.expression.AnnotatedElementKey) Test(org.junit.Test)

Example 9 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() {
    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<>();
    resolvers.add(new CachingResourceResolver(this.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) Before(org.junit.Before)

Example 10 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)

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