本文整理汇总了Java中org.springframework.cache.concurrent.ConcurrentMapCache类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentMapCache类的具体用法?Java ConcurrentMapCache怎么用?Java ConcurrentMapCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentMapCache类属于org.springframework.cache.concurrent包,在下文中一共展示了ConcurrentMapCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resourceChain
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@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));
}
示例2: testPut
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Test
public void testPut() throws Exception {
Cache proxy = new ConcurrentMapCache("foo");
proxy.put("bar", "value");
proxy.put("baz", "value");
FluuzCache fluuzCache = new FluuzCache(eventManager, proxy);
eventManager.register(fluuzCache);
Thread.sleep(2000);
eventManager.evict("foo", "bar");
Thread.sleep(2000);
String value = null;
ValueWrapper vw = proxy.get("bar");
if (vw == null) {
}
System.out.println("->" + value);
}
示例3: testMultipleCachingEval
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@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 = eval.createEvaluationContext(caches, method, args, target, target.getClass());
Collection<CacheOperation> ops = getOps("multipleCaching");
Iterator<CacheOperation> it = ops.iterator();
AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);
Object keyA = eval.key(it.next().getKey(), key, evalCtx);
Object keyB = eval.key(it.next().getKey(), key, evalCtx);
assertEquals(args[0], keyA);
assertEquals(args[1], keyB);
}
示例4: setUp
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@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()));
}
示例5: evictTransactional
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@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));
}
示例6: clearTransactional
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@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));
}
示例7: testMultipleCachingEval
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
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<Cache> map = Collections.singleton(new ConcurrentMapCache("test"));
EvaluationContext evalCtx = eval.createEvaluationContext(map, method, args, target, target.getClass());
Collection<CacheOperation> ops = getOps("multipleCaching");
Iterator<CacheOperation> it = ops.iterator();
Object keyA = eval.key(it.next().getKey(), method, evalCtx);
Object keyB = eval.key(it.next().getKey(), method, evalCtx);
assertEquals(args[0], keyA);
assertEquals(args[1], keyB);
}
示例8: listOneElementCached
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Test
public void listOneElementCached() throws StratioEngineStatusException, StratioAPIGenericException, StratioEngineConnectionException, StratioEngineOperationException {
String streamName = "testStream";
List<ColumnNameTypeValue> values = new ArrayList<>();
values.add(new ColumnNameTypeValue("column1", ColumnType.STRING, null));
values.add(new ColumnNameTypeValue("column2", ColumnType.INTEGER, null));
values.add(new ColumnNameTypeValue("column3", ColumnType.BOOLEAN, null));
List<StratioStream> streams = new ArrayList<>();
StratioStream stream = new StratioStream(streamName, values, new ArrayList<StreamQuery>(),
new HashSet<StreamAction>(), true);
streams.add(stream);
Mockito.when(ssaw.api().listStreams()).thenReturn(streams);
cachedStreamsDAO.listStreams();
int cacheSize = ((ConcurrentMapCache) cacheManager.getCache("streams")).getNativeCache().size();
assertEquals(1, cacheSize);
}
示例9: listOneElementCachedAndRefreshed
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Test
public void listOneElementCachedAndRefreshed() throws StratioEngineStatusException, StratioAPIGenericException, StratioEngineConnectionException, StratioEngineOperationException, StratioEngineOperationException {
String streamName = "testStream";
List<ColumnNameTypeValue> values = new ArrayList<>();
values.add(new ColumnNameTypeValue("column1", ColumnType.STRING, null));
values.add(new ColumnNameTypeValue("column2", ColumnType.INTEGER, null));
values.add(new ColumnNameTypeValue("column3", ColumnType.BOOLEAN, null));
List<StratioStream> streams = new ArrayList<>();
StratioStream stream = new StratioStream(streamName, values, new ArrayList<StreamQuery>(),
new HashSet<StreamAction>(), true);
streams.add(stream);
Mockito.when(ssaw.api().listStreams()).thenReturn(streams);
cachedStreamsDAO.listStreams();
CommandResult cr = shell.executeCommand("list");
int cacheSize = ((ConcurrentMapCache) cacheManager.getCache("streams")).getNativeCache().size();
assertEquals(true, cr.isSuccess());
assertEquals(1, cacheSize);
}
示例10: gaugeCacheSize
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Test
public void gaugeCacheSize() {
ConcurrentMapCache cache = new ConcurrentMapCache("a");
cache.put("k", "v");
MeterRegistry registry = new SimpleMeterRegistry();
new ConcurrentMapCacheMetrics(cache, "spring.cache", emptyList()).bindTo(registry);
assertThat(registry.mustFind("spring.cache.size").tags("name", "a")
.gauge().value()).isEqualTo(1.0);
}
示例11: createEvaluationContext
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
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;
}
示例12: parseResourceCache
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
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);
}
}
示例13: setup
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@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()));
}
示例14: testResourcesWithResolversTransformers
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Test
public void testResourcesWithResolversTransformers() throws Exception {
loadBeanDefinitions("mvc-config-resources-chain.xml", 11);
SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
assertNotNull(mapping);
assertNotNull(mapping.getUrlMap().get("/resources/**"));
ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"),
ResourceHttpRequestHandler.class);
assertNotNull(handler);
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers, Matchers.hasSize(4));
assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
assertThat(resolvers.get(1), Matchers.instanceOf(VersionResourceResolver.class));
assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));
CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertEquals("test-resource-cache", cachingResolver.getCache().getName());
VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(1);
assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
Matchers.instanceOf(FixedVersionStrategy.class));
assertThat(versionResolver.getStrategyMap().get("/**"),
Matchers.instanceOf(ContentVersionStrategy.class));
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(3));
assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));
CachingResourceTransformer cachingTransformer = (CachingResourceTransformer) transformers.get(0);
assertThat(cachingTransformer.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertEquals("test-resource-cache", cachingTransformer.getCache().getName());
}
示例15: cacheManager
import org.springframework.cache.concurrent.ConcurrentMapCache; //导入依赖的package包/类
@Bean
public CacheManager cacheManager() {
SimpleCacheManager mgr = new SimpleCacheManager();
ArrayList<Cache> caches = new ArrayList<Cache>();
caches.add(new ConcurrentMapCache(""));
mgr.setCaches(caches);
return mgr;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:EnableTransactionManagementIntegrationTests.java