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


Java Caching类代码示例

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


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

示例1: before

import javax.cache.Caching; //导入依赖的package包/类
@Before
public void before() throws Exception {
  CachingProvider cachingProvider = Caching.getCachingProvider();
  EhcacheCachingProvider ehcacheProvider = (EhcacheCachingProvider) cachingProvider;

  DefaultConfiguration configuration = new DefaultConfiguration(ehcacheProvider.getDefaultClassLoader(),
    new DefaultPersistenceConfiguration(diskPath.newFolder()));

  CacheConfiguration<Integer, String> cacheConfiguration =
    CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, String.class, resources).build();
  configuration.addCacheConfiguration("cache", cacheConfiguration);

  cacheManager = ehcacheProvider.getCacheManager(ehcacheProvider.getDefaultURI(), configuration);

  EhcacheManager ehcacheManager = cacheManager.unwrap(EhcacheManager.class);
  Field field = EhcacheManager.class.getDeclaredField("serviceLocator");
  field.setAccessible(true);
  @SuppressWarnings("unchecked")
  ServiceProvider<Service> serviceProvider = (ServiceProvider<Service>)field.get(ehcacheManager);
  StatisticsService statisticsService = serviceProvider.getService(StatisticsService.class);

  cache = cacheManager.getCache("cache", Integer.class, String.class);

  cacheStatistics = statisticsService.getCacheStatistics("cache");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:26,代码来源:JCacheCalculationTest.java

示例2: testRedissonConfig

import javax.cache.Caching; //导入依赖的package包/类
@Test
public void testRedissonConfig() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .port(6311)
            .run();
    
    URL configUrl = getClass().getResource("redisson-jcache.json");
    Config cfg = Config.fromJSON(configUrl);
    
    Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager()
            .createCache("test", config);
    
    cache.put("1", "2");
    Assert.assertEquals("2", cache.get("1"));
    
    cache.close();
    runner.stop();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:JCacheTest.java

示例3: getCacheManagerWithNonNullProperties

import javax.cache.Caching; //导入依赖的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

示例4: init

import javax.cache.Caching; //导入依赖的package包/类
@Before
public void init()
{
    cachingProvider = Caching.getCachingProvider(GuavaCachingProvider.class.getName());
    assertNotNull(cachingProvider);

    cacheManager = cachingProvider.getCacheManager();
    assertNotNull(cacheManager);

    configuration.setStoreByValue(false);
    configuration.setTypes(String.class, Integer.class);

    cache = cacheManager.createCache("cache", configuration);
    assertNotNull(cache);
    assertEquals("cache", cache.getName());
    assertEquals(cacheManager, cache.getCacheManager());
    assertEquals(configuration, cache.getConfiguration(MutableConfiguration.class));
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:19,代码来源:GuavaCacheTest.java

示例5: testGetCachingProviders

import javax.cache.Caching; //导入依赖的package包/类
@Test
public void testGetCachingProviders()
{
    int instances = 0;

    for (CachingProvider cp : Caching.getCachingProviders())
    {
        if (cp.getClass().getName().equals(GuavaCachingProvider.class.getName()))
        {
            instances++;
        }

        cp.close();
    }

    assertEquals(1, instances);
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:18,代码来源:GuavaCachingProviderTest.java

示例6: call

import javax.cache.Caching; //导入依赖的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

示例7: ehCacheManager

import javax.cache.Caching; //导入依赖的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

示例8: getMatchOutcome

import javax.cache.Caching; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
			context.getEnvironment(), "spring.cache.jcache.");
	if (resolver.containsProperty("provider")) {
		return ConditionOutcome.match("JCache provider specified");
	}
	Iterator<CachingProvider> providers = Caching.getCachingProviders()
			.iterator();
	if (!providers.hasNext()) {
		return ConditionOutcome.noMatch("No JSR-107 compliant providers");
	}
	providers.next();
	if (providers.hasNext()) {
		return ConditionOutcome.noMatch(
				"Multiple default JSR-107 compliant " + "providers found");

	}
	return ConditionOutcome.match("Default JSR-107 compliant provider found.");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:JCacheCacheConfiguration.java

示例9: createManager

import javax.cache.Caching; //导入依赖的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

示例10: getCertificateCache

import javax.cache.Caching; //导入依赖的package包/类
public static Cache<String, CertificateResponse> getCertificateCache() {
    DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
    CacheManager manager = getCacheManager();
    Cache<String, CertificateResponse> certificateCache = null;
    if (config.getDeviceCacheConfiguration().isEnabled()) {
        if (!isCertificateCacheInitialized) {
            initializeCertificateCache();
        }
        if (manager != null) {
            certificateCache = manager.<String, CertificateResponse>getCache(CertificateCacheManagerImpl.CERTIFICATE_CACHE);
        } else {
            certificateCache = Caching.getCacheManager(CertificateCacheManagerImpl.CERTIFICATE_CACHE_MANAGER).
                    <String, CertificateResponse>getCache(CertificateCacheManagerImpl.CERTIFICATE_CACHE);
        }
    }
    return certificateCache;
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:18,代码来源:CertificateCacheManagerImpl.java

示例11: getDeviceCache

import javax.cache.Caching; //导入依赖的package包/类
public static Cache<DeviceCacheKey, Device> getDeviceCache() {
    DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
    CacheManager manager = getCacheManager();
    Cache<DeviceCacheKey, Device> deviceCache = null;
    if (config.getDeviceCacheConfiguration().isEnabled()) {
        if(!isDeviceCacheInitialized) {
            initializeDeviceCache();
        }
        if (manager != null) {
            deviceCache = manager.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
        } else {
            deviceCache =  Caching.getCacheManager(DeviceManagementConstants.DM_CACHE_MANAGER).
                    <DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
        }
    }
    return deviceCache;
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:18,代码来源:DeviceManagerUtil.java

示例12: setup

import javax.cache.Caching; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(new H2());
    EntityModel model = Models.JPA;

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        .setEntityCache(new EntityCacheBuilder(model)
            .useReferenceCache(true)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build())
        .build();
    data = new EntityDataStore<>(configuration);
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.dropTables();
    TableCreationMode mode = TableCreationMode.CREATE;
    System.out.println(tables.createTablesString(mode));
    tables.createTables(mode);
}
 
开发者ID:requery,项目名称:requery,代码行数:23,代码来源:JPAModelTest.java

示例13: setup

import javax.cache.Caching; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        .setWriteExecutor(Executors.newSingleThreadExecutor())
        .setEntityCache(new EntityCacheBuilder(model)
            .useReferenceCache(true)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build())
        .build();

    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = new ReactorEntityStore<>(new EntityDataStore<Persistable>(configuration));
}
 
开发者ID:requery,项目名称:requery,代码行数:23,代码来源:ReactorTest.java

示例14: testSerializeGetPut

import javax.cache.Caching; //导入依赖的package包/类
@Test
public void testSerializeGetPut() {
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();

    EntityCache cache = new EntityCacheBuilder(Models.DEFAULT)
            .useReferenceCache(false)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build();

    Person p = new Person();
    p.setName("Alice");
    p.setUUID(UUID.randomUUID());
    p.setAddress(new Address());
    p.getAddress().setType(AddressType.HOME);

    int id = 100;
    cache.put(Person.class, id, p);

    Person d = cache.get(Person.class, id);
    Assert.assertNotNull(d);
    Assert.assertNotSame(p, d);
    Assert.assertEquals(p.getName(), d.getName());
    Assert.assertEquals(p.getUUID(), d.getUUID());
}
 
开发者ID:requery,项目名称:requery,代码行数:27,代码来源:EntityCacheTest.java

示例15: setup

import javax.cache.Caching; //导入依赖的package包/类
@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        .setWriteExecutor(Executors.newSingleThreadExecutor())
        .setEntityCache(new EntityCacheBuilder(model)
            .useReferenceCache(true)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build())
        .build();

    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = ReactiveSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
 
开发者ID:requery,项目名称:requery,代码行数:23,代码来源:ReactiveTest.java


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