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));
}
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));
}
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);
}
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()));
}
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()));
}
Aggregations