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


Java CachingProvider类代码示例

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


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

示例1: before

import javax.cache.spi.CachingProvider; //导入依赖的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: cacheExposesMetrics

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

示例3: getCacheManagerWithNonNullProperties

import javax.cache.spi.CachingProvider; //导入依赖的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: testGetCachingProviders

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

示例5: call

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

示例6: ehCacheManager

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

示例7: getMatchOutcome

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

示例8: createManager

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

示例9: setup

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

示例10: setup

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

示例11: testSerializeGetPut

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

示例12: setup

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

示例13: setup

import javax.cache.spi.CachingProvider; //导入依赖的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 = RxSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
 
开发者ID:requery,项目名称:requery,代码行数:23,代码来源:RxTest.java

示例14: JCacheTemplateCache

import javax.cache.spi.CachingProvider; //导入依赖的package包/类
public JCacheTemplateCache() {
    Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
    if (cachingProviders.hasNext()) {
        CachingProvider cachingProvider = cachingProviders.next();
        CacheManager cacheManager = cachingProvider.getCacheManager();
        Configuration<String, Template> config = new MutableConfiguration<String, Template>()
                .setTypes(String.class, Template.class)
                .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
        Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
        if (cache == null) {
            this.cache = cacheManager.createCache("TemplateCache", config);
        } else {
            this.cache = cache;
        }
    } else {
        this.cache = null; // to keep compatibility with 0.1.0, but ugly
    }
}
 
开发者ID:kawasima,项目名称:moshas,代码行数:19,代码来源:JCacheTemplateCache.java

示例15: testStatistics

import javax.cache.spi.CachingProvider; //导入依赖的package包/类
@Test
public void testStatistics() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        MutableConfiguration<String, String> config
                = new MutableConfiguration<String, String>()
                .setTypes(String.class, String.class)
                .setStatisticsEnabled(true)
                .setManagementEnabled(true);
        BlazingCacheCache<String, String> cache = cacheManager.createCache("simpleCache", config).unwrap(BlazingCacheCache.class);
        BlazingCacheStatisticsMXBean<String, String> stats = cache.getStatisticsMXBean();
        cache.put("1", "test");
        cache.get("1");
        assertEquals(1L, stats.getCachePuts());
        assertEquals(1L, stats.getCacheGets());
        assertEquals(1L, stats.getCacheHits());
        cache.get("2");
        assertEquals(1L, stats.getCacheMisses());
        stats.clear();
        assertEquals(0L, stats.getCachePuts());
        assertEquals(0L, stats.getCacheGets());
        assertEquals(0L, stats.getCacheHits());
        assertEquals(0L, stats.getCacheMisses());
    }
}
 
开发者ID:diennea,项目名称:blazingcache,代码行数:27,代码来源:ManagementTest.java


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