当前位置: 首页>>代码示例>>Java>>正文


Java CacheManager类代码示例

本文整理汇总了Java中javax.cache.CacheManager的典型用法代码示例。如果您正苦于以下问题:Java CacheManager类的具体用法?Java CacheManager怎么用?Java CacheManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CacheManager类属于javax.cache包,在下文中一共展示了CacheManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cacheExposesMetrics

import javax.cache.CacheManager; //导入依赖的package包/类
@ParameterizedTest
@MethodSource("cachingProviders")
void cacheExposesMetrics(CachingProvider provider) {
    CacheManager cacheManager = provider.getCacheManager();

    MutableConfiguration<Integer, String> configuration = new MutableConfiguration<>();
    configuration.setTypes(Integer.class, String.class)
        .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
        .setStatisticsEnabled(true);

    Cache<Integer, String> cache = cacheManager.createCache("a", configuration);
    cache.put(1, "test");

    MeterRegistry registry = new SimpleMeterRegistry();
    JCacheMetrics.monitor(registry, cache, "jcache", emptyList());

    assertThat(registry.mustFind("jcache.puts").tags("name", "a").gauge().value()).isEqualTo(1.0);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:19,代码来源:JCacheMetricsTest.java

示例2: createCache

import javax.cache.CacheManager; //导入依赖的package包/类
/**
 * Create a new cache from the given cache manager.
 *
 * @param cacheName         Name of the cache.
 * @param keyClass          Type of the key class.
 * @param valueClass        Type of the value class.
 * @param defaultExpiryTime Cache expire time in minutes.
 * @param cacheConfigMap    Cache config map.
 * @param cacheManager      Cache manager to use to create the cache.
 * @param <K>               Type of the Key.
 * @param <V>               Type of the Value.
 * @return Created cache.
 */
public static <K, V> Cache<K, V> createCache(String cacheName, Class<K> keyClass, Class<V> valueClass,
                                             int defaultExpiryTime, Map<String, CacheConfig> cacheConfigMap,
                                             CacheManager cacheManager) {

    Duration cacheExpiry = new Duration(TimeUnit.MINUTES, getExpireTime(cacheConfigMap, cacheName,
            defaultExpiryTime));

    boolean isStatisticsEnabled = false;

    if (cacheConfigMap.get(cacheName) != null) {
        isStatisticsEnabled = cacheConfigMap.get(cacheName).isStatisticsEnabled();
    }

    MutableConfiguration<K, V> configuration = new MutableConfiguration<>();
    configuration.setStoreByValue(false)
            .setTypes(keyClass, valueClass)
            .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(cacheExpiry))
            .setStatisticsEnabled(isStatisticsEnabled);

    return cacheManager.createCache(cacheName, configuration);
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:35,代码来源:CacheHelper.java

示例3: getCacheManager

import javax.cache.CacheManager; //导入依赖的package包/类
@Override
public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties)
{
    URI _uri = (uri != null) ? uri : getDefaultURI();
    ClassLoader _classLoader = (classLoader != null) ? classLoader : getDefaultClassLoader();
    Properties _properties = (properties != null) ? properties : new Properties();

    CacheManager newCacheManager = new GuavaCacheManager(_uri, _classLoader, _properties, this);

    CacheManager oldCacheManager = cacheManagers.putIfAbsent(new Pair<>(_uri, _classLoader), newCacheManager);

    if (oldCacheManager != null)
    {
        return oldCacheManager;
    }

    return newCacheManager;
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:19,代码来源:GuavaCachingProvider.java

示例4: close

import javax.cache.CacheManager; //导入依赖的package包/类
@Override
public void close()
{
    Iterator<Map.Entry<Pair<URI, ClassLoader>, CacheManager>> i = cacheManagers.entrySet().iterator();

    while (i.hasNext())
    {
        Map.Entry<Pair<URI, ClassLoader>, CacheManager> entry = i.next();

        CacheManager cm = entry.getValue();

        if (cm != null && !cm.isClosed())
        {
            cm.close();
        }

        i.remove();
    }
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:20,代码来源:GuavaCachingProvider.java

示例5: testCacheManagerWithCustomClassLoader

import javax.cache.CacheManager; //导入依赖的package包/类
@Test
public void testCacheManagerWithCustomClassLoader()
    throws Exception
{
    CacheManager cacheManager1 = cachingProvider.getCacheManager();
    CacheManager cacheManager2 = cachingProvider.getCacheManager(null, ClassLoader.getSystemClassLoader());

    assertNotNull(cacheManager1);
    assertNotNull(cacheManager2);

    assertNotEquals(cacheManager1, cacheManager2);

    cacheManager1.close();
    cacheManager2.close();

    assertTrue(cacheManager1.isClosed());
    assertTrue(cacheManager2.isClosed());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:19,代码来源:GuavaCacheManagerTest.java

示例6: testCacheManagerWithCustomProperties

import javax.cache.CacheManager; //导入依赖的package包/类
@Test
public void testCacheManagerWithCustomProperties()
    throws Exception
{
    Properties properties = new Properties();

    properties.setProperty("concurrencyLevel", "1");
    properties.setProperty("initialCapacity", "16");

    CacheManager cacheManager1 = cachingProvider.getCacheManager();
    CacheManager cacheManager2 = cachingProvider.getCacheManager(null, null, properties);

    assertNotNull(cacheManager1);
    assertNotNull(cacheManager2);

    // properties do not form part of the identity of the CacheManager
    assertEquals(cacheManager1, cacheManager2);

    cacheManager1.close();
    cacheManager2.close();

    assertTrue(cacheManager1.isClosed());
    assertTrue(cacheManager2.isClosed());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:25,代码来源:GuavaCacheManagerTest.java

示例7: testCacheManagerWithCustomInvalidProperties

import javax.cache.CacheManager; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testCacheManagerWithCustomInvalidProperties()
    throws Exception
{
    Properties properties = new Properties();

    properties.setProperty("unknownProperty", "true");

    try (CacheManager cacheManager = cachingProvider.getCacheManager(null, null, properties);)
    {
        assertNotNull(cacheManager);

        MutableConfiguration configuration = new MutableConfiguration();

        configuration.setStoreByValue(false);

        cacheManager.createCache("test", configuration);
    }
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:20,代码来源:GuavaCacheManagerTest.java

示例8: testCacheManagerWithCustomClassLoaderAndProperties

import javax.cache.CacheManager; //导入依赖的package包/类
@Test
public void testCacheManagerWithCustomClassLoaderAndProperties()
    throws Exception
{
    Properties properties = new Properties();

    properties.setProperty("concurrencyLevel", "1");
    properties.setProperty("initialCapacity", "16");

    CacheManager cacheManager1 = cachingProvider.getCacheManager();
    CacheManager cacheManager2 =
        cachingProvider.getCacheManager(null, ClassLoader.getSystemClassLoader(), properties);

    assertNotNull(cacheManager1);
    assertNotNull(cacheManager2);

    assertNotEquals(cacheManager1, cacheManager2);

    cacheManager1.close();
    cacheManager2.close();

    assertTrue(cacheManager1.isClosed());
    assertTrue(cacheManager2.isClosed());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:25,代码来源:GuavaCacheManagerTest.java

示例9: testCreateCacheWithModifiedExpiryPolicy

import javax.cache.CacheManager; //导入依赖的package包/类
@Test
public void testCreateCacheWithModifiedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY));

    Cache cache = cacheManager.createCache("cache", configuration);

    CompleteConfiguration actualConfiguration =
        (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);

    assertEquals(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY), actualConfiguration.getExpiryPolicyFactory());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:18,代码来源:GuavaCacheManagerTest.java

示例10: testCreateCacheWithTouchedExpiryPolicy

import javax.cache.CacheManager; //导入依赖的package包/类
@Test
public void testCreateCacheWithTouchedExpiryPolicy()
{
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();

    configuration.setStoreByValue(false);
    configuration.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));

    Cache cache = cacheManager.createCache("cache", configuration);

    CompleteConfiguration actualConfiguration =
        (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);

    assertEquals(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE), actualConfiguration.getExpiryPolicyFactory());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:18,代码来源:GuavaCacheManagerTest.java

示例11: getCacheManagerWithNonNullProperties

import javax.cache.CacheManager; //导入依赖的package包/类
@Test // org.jsr107.tck.CacheManagerTest.getCacheManager_nonNullProperties
public void getCacheManagerWithNonNullProperties()
{
    // see https://github.com/jsr107/jsr107tck/issues/102

    // make sure existing cache managers are closed and the non empty properties get picked up
    try
    {
        Caching.getCachingProvider().close();
    }
    catch (CacheException ignore)
    {
        // ignore exception which may happen if the provider is not active
    }

    CachingProvider provider = Caching.getCachingProvider();

    Properties properties = new Properties();
    properties.put("dummy.com", "goofy");

    provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(), properties);
    CacheManager manager = provider.getCacheManager();

    assertEquals(properties, manager.getProperties());
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:26,代码来源:GuavaCacheManagerTest.java

示例12: call

import javax.cache.CacheManager; //导入依赖的package包/类
@Override
public Collection<ValueObject> call()
    throws Exception
{
    CachingProvider cachingProvider = Caching.getCachingProvider(GuavaCachingProvider.class.getName());

    CacheManager cacheManager = cachingProvider.getCacheManager();

    Cache<KeyObject, ValueObject> cache =
        cacheManager.getCache("workerCache", KeyObject.class, ValueObject.class);

    Set<ValueObject> values = new HashSet<>();

    for (long id = 0; id < TEST_CACHE_SIZE; id++)
    {
        values.add(cache.get(new KeyObject(id)));
    }

    return values;
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:21,代码来源:GuavaCacheConcurrentTest.java

示例13: ehCacheManager

import javax.cache.CacheManager; //导入依赖的package包/类
@Bean
@Primary
public CacheManager ehCacheManager(JiraSyncConfig jiraSyncConfig) throws Exception {
	CachingProvider cachingProvider = Caching.getCachingProvider();
	EhcacheCachingProvider ehcacheCachingProvider = (EhcacheCachingProvider) cachingProvider;
	CacheConfig cacheConfig = jiraSyncConfig.getCache();
	CacheManager cacheManager = getCacheManager(ehcacheCachingProvider, cacheConfig);
	boolean persistentCache = cacheConfig.isPersistent();
	createCache(cacheManager, CACHE_NAME_PROJECTS, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_PRIORITIES, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_RESOLUTIONS, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_VERSIONS, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_FIELDS, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_REMOTE_LINKS, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_USERS, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_FIELD_ALLOWED_VALUES, ONE_HOUR, persistentCache);
	createCache(cacheManager, CACHE_NAME_MYSELF, ONE_HOUR, false);
	createCache(cacheManager, CACHE_NAME_SERVER_INFO, THIRTY_SECONDS, false);
	return cacheManager;
}
 
开发者ID:cronn-de,项目名称:jira-sync,代码行数:21,代码来源:JiraServiceCacheConfig.java

示例14: createCache

import javax.cache.CacheManager; //导入依赖的package包/类
private void createCache(CacheManager cacheManager, String cacheName, Duration timeToLive, boolean persistentCache) {
	ResourcePoolsBuilder resourcePoolsBuilder = ResourcePoolsBuilder.heap(100);
	if (persistentCache) {
		resourcePoolsBuilder = resourcePoolsBuilder.disk(1, MemoryUnit.MB, true);
	}
	CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
		resourcePoolsBuilder)
		.withExpiry(Expirations.timeToLiveExpiration(timeToLive))
		.build();

	for (String cache : cacheManager.getCacheNames()) {
		if (cache.equals(cacheName)) {
			log.warn("cache '{}' already exists. skipping creation", cacheName);
			return;
		}
	}

	cacheManager.createCache(cacheName, Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));
}
 
开发者ID:cronn-de,项目名称:jira-sync,代码行数:20,代码来源:JiraServiceCacheConfig.java

示例15: createManager

import javax.cache.CacheManager; //导入依赖的package包/类
public CacheManager createManager(Map<String, Configuration<?, ?>> configs, ShutdownManager shutdownManager) {

        CachingProvider provider;
        try {
            // TODO: an explicit config property to pick explicit provider out of available choices... though probably
            // pointless in most cases (do we realistically expect multiple providers on classpath?)
            provider = Caching.getCachingProvider();
        } catch (CacheException e) {
            throw new RuntimeException("'bootique-jcache' doesn't bundle any JCache providers. " +
                    "You must place a JCache 1.0 provider on classpath explicitly.", e);
        }

        shutdownManager.addShutdownHook(provider);

        CacheManager manager = getConfigUri().map(u -> provider.getCacheManager(u, null)).orElse(provider.getCacheManager());
        shutdownManager.addShutdownHook(manager);

        // now load contributed configs
        configs.forEach(manager::createCache);

        return manager;
    }
 
开发者ID:bootique,项目名称:bootique-jcache,代码行数:23,代码来源:JCacheFactory.java


注:本文中的javax.cache.CacheManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。