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


Java Cache.put方法代码示例

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


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

示例1: testRedissonConfig

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

示例2: run

import javax.cache.Cache; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {

    //retrieve the cache defined in the declaration file hazelcast.xml
    Cache<String, Integer> declarativeCache = cacheManager.get()
            .getCache("myCache1", String.class, Integer.class);

    //put an entry...
    //CacheEntryCreatedListener fires afterwards
    declarativeCache.put("1", 1);

    //retrieve the cache configured programmatically and contributed into Bootique
    Cache<String, String> programmaticCache = cacheManager.get()
            .getCache("myCache2", String.class, String.class);

    //put an entry...
    //CacheEntryCreatedListener fires afterwards
    programmaticCache.put("key1", "value1");

    return CommandOutcome.succeeded();
}
 
开发者ID:bootique-examples,项目名称:bootique-jcache-demo,代码行数:22,代码来源:DemoHazelcastCommand.java

示例3: run

import javax.cache.Cache; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {

    //retrieve the cache defined in ehcache.xml
    Cache<String, Integer> cache = cacheManager.get()
            .getCache("myCache1", String.class, Integer.class);

    //put an entry...
    //CacheEntryCreatedListener fires afterwards
    cache.put("1", 1);

    //retrieve the cache configured programmatically and contributed into Bootique
    Cache<Long, Long> myCache2 = cacheManager.get()
            .getCache("myCache2", Long.class, Long.class);

    //put an entry...
    //CacheEntryCreatedListener fires afterwards
    myCache2.put(1L, 1L);

    return CommandOutcome.succeeded();
}
 
开发者ID:bootique-examples,项目名称:bootique-jcache-demo,代码行数:22,代码来源:DemoEhcacheCommand.java

示例4: cacheExposesMetrics

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

示例5: testRedissonInstance

import javax.cache.Cache; //导入方法依赖的package包/类
@Test
public void testRedissonInstance() throws InterruptedException, IllegalArgumentException, URISyntaxException {
    Configuration<String, String> config = RedissonConfiguration.fromInstance(redisson);
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager()
            .createCache("test", config);
    
    cache.put("1", "2");
    Assert.assertEquals("2", cache.get("1"));
    
    cache.close();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:JCacheTest.java

示例6: testExpiration

import javax.cache.Cache; //导入方法依赖的package包/类
@Test
public void testExpiration() throws InterruptedException, IllegalArgumentException, URISyntaxException, FailedToStartRedisException, IOException {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .port(6311)
            .run();

    MutableConfiguration<String, String> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
    config.setStoreByValue(true);
    
    URI configUri = getClass().getResource("redisson-jcache.json").toURI();
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager(configUri, null)
            .createCache("test", config);

    CountDownLatch latch = new CountDownLatch(1);
    
    String key = "123";
    ExpiredListener clientListener = new ExpiredListener(latch, key, "90");
    MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = 
            new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(clientListener), null, true, true);
    cache.registerCacheEntryListener(listenerConfiguration);

    cache.put(key, "90");
    Assert.assertNotNull(cache.get(key));
    
    latch.await();
    
    Assert.assertNull(cache.get(key));
    
    cache.close();
    runner.stop();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:35,代码来源:JCacheTest.java


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