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


Java MutableConfiguration.setCacheLoaderFactory方法代码示例

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


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

示例1: getOrCreateCacheConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
Configuration getOrCreateCacheConfiguration() {
    if (configuration.getCacheConfiguration() != null) {
        return configuration.getCacheConfiguration();
    }

    MutableConfiguration mutableConfiguration = new MutableConfiguration();
    if (configuration.getCacheLoaderFactory() != null) {
        mutableConfiguration.setCacheLoaderFactory(configuration.getCacheLoaderFactory());
    }
    if (configuration.getCacheWriterFactory() != null) {
        mutableConfiguration.setCacheWriterFactory(configuration.getCacheWriterFactory());
    }
    if (configuration.getExpiryPolicyFactory() != null) {
        mutableConfiguration.setExpiryPolicyFactory(configuration.getExpiryPolicyFactory());
    }

    mutableConfiguration.setManagementEnabled(configuration.isManagementEnabled());
    mutableConfiguration.setStatisticsEnabled(configuration.isStatisticsEnabled());
    mutableConfiguration.setReadThrough(configuration.isReadThrough());
    mutableConfiguration.setStoreByValue(configuration.isStoreByValue());

    return mutableConfiguration;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:JCacheManager.java

示例2: testLoaderConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testLoaderConfiguration() throws Exception {
  final AtomicBoolean loaderCreated = new AtomicBoolean(false);

  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class).setReadThrough(true);
  configuration.setCacheLoaderFactory(() -> {
    loaderCreated.set(true);
    return new TestCacheLoader();
  });

  CachingProvider provider = Caching.getCachingProvider();
  CacheManager cacheManager = provider.getCacheManager();
  Cache<String, String> cache = cacheManager.createCache("cache", configuration);

  assertThat(loaderCreated.get(), is(true));

  cache.putIfAbsent("42", "The Answer");

  TestCacheLoader.seen.clear();
  CompletionListenerFuture future = new CompletionListenerFuture();
  cache.loadAll(Collections.singleton("42"), true, future);
  future.get();

  assertThat(TestCacheLoader.seen, contains("42"));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:SimpleEh107ConfigTest.java

示例3: onBeforeEachTest

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
 * Establish the {@link javax.cache.CacheManager} and {@link javax.cache.Cache} for a test.
 */
@Before
public void onBeforeEachTest() throws IOException {
  //establish and open a CacheLoaderServer to handle cache
  //cache loading requests from a CacheLoaderClient
  cacheLoaderServer = new CacheLoaderServer<String, String>(10000);
  cacheLoaderServer.open();

  //establish the CacheManager for the tests
  cacheManager = Caching.getCachingProvider().getCacheManager();

  //establish a CacheLoaderClient that a Cache can use for loading entries
  //(via the CacheLoaderServer)
  CacheLoaderClient<String, String> cacheLoader =
      new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());

  //establish a Cache Configuration that uses a CacheLoader (no Read-Through)
  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class);
  configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
  configuration.setReadThrough(false);

  //configure the cache
  cacheManager.createCache("cache-loader-test", configuration);
  cache = cacheManager.getCache("cache-loader-test", String.class, String.class);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:29,代码来源:CacheLoaderWithoutReadThroughTest.java

示例4: onBeforeEachTest

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
 * Establish the {@link CacheManager} and {@link Cache} for a test.
 */
@Before
public void onBeforeEachTest() throws IOException {
  //establish and open a CacheLoaderServer to handle cache
  //cache loading requests from a CacheLoaderClient
  cacheLoaderServer = new CacheLoaderServer<String, String>(10000);
  cacheLoaderServer.open();

  //establish the CacheManager for the tests
  cacheManager = Caching.getCachingProvider().getCacheManager();

  //establish a CacheLoaderClient that a Cache can use for loading entries
  //(via the CacheLoaderServer)
  CacheLoaderClient<String, String> cacheLoader =
      new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());

  //establish a Cache Configuration that uses a CacheLoader and Read-Through
  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class);
  configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
  configuration.setReadThrough(true);

  //configure the cache
  cacheManager.createCache("cache-loader-test", configuration);
  cache = cacheManager.getCache("cache-loader-test", String.class, String.class);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:29,代码来源:CacheLoaderTest.java

示例5: invokeAllReadThroughEnabledGetOnNonExistentEntry

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeAllReadThroughEnabledGetOnNonExistentEntry() throws IOException {
    //establish and open a CacheLoaderServer to handle cache
    //cache loading requests from a CacheLoaderClient

    // this cacheLoader just returns the key as the value.
    RecordingCacheLoader<Integer> recordingCacheLoader = new RecordingCacheLoader<>();

    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();

    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicy));
    config.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(recordingCacheLoader));
    config.setReadThrough(true);

    Cache<Integer, Integer> cache = getCacheManager().createCache("test-1", config);

    final Integer INITIAL_KEY = 123;
    final Integer MAX_KEY_VALUE = INITIAL_KEY + 4;

    // set keys to read through
    Set<Integer> keys = new HashSet<>();
    for (int key = INITIAL_KEY; key <= MAX_KEY_VALUE; key++) {
        keys.add(key);
    }

    // verify read-through of getValue of non-existent entries
    cache.invokeAll(keys, new GetEntryProcessor<Integer, Integer>());

    assertTrue(expiryPolicy.getCreationCount() >= keys.size());
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
    expiryPolicy.resetCount();

}
 
开发者ID:diennea,项目名称:blazingcache,代码行数:36,代码来源:TCKCacheManagerTest.java

示例6: test107LoaderOverriddenByEhcacheTemplateLoaderWriter

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void test107LoaderOverriddenByEhcacheTemplateLoaderWriter() throws Exception {
  final AtomicBoolean loaderFactoryInvoked = new AtomicBoolean(false);
  final DumbCacheLoader product2CacheLoader = new DumbCacheLoader();

  MutableConfiguration<Long, Product> product2Configuration = new MutableConfiguration<>();
  product2Configuration.setTypes(Long.class, Product.class).setReadThrough(true);
  product2Configuration.setCacheLoaderFactory(() -> {
    loaderFactoryInvoked.set(true);
    return product2CacheLoader;
  });

  Cache<Long, Product> productCache2 = cacheManager.createCache("productCache2", product2Configuration);

  assertThat(loaderFactoryInvoked.get(), is(false));

  Product product = productCache2.get(124L);
  assertThat(product.getId(), is(124L));
  assertThat(ProductCacheLoaderWriter.seen, hasItem(124L));
  assertThat(product2CacheLoader.seen, is(empty()));

  CompletionListenerFuture future = new CompletionListenerFuture();
  productCache2.loadAll(Collections.singleton(42L), false, future);
  future.get();
  assertThat(ProductCacheLoaderWriter.seen, hasItem(42L));
  assertThat(product2CacheLoader.seen, is(empty()));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:28,代码来源:Eh107XmlIntegrationTest.java

示例7: jsr107LoaderInitAlways

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void jsr107LoaderInitAlways() {
  CacheLoader<Object, Object> loader = mock(CacheLoader.class);

  MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>();
  RecordingFactory<CacheLoader<Object, Object>> factory = factoryOf(loader);
  configuration.setCacheLoaderFactory(factory);

  ConfigurationMerger.ConfigHolder<Object, Object> configHolder = merger.mergeConfigurations("cache", configuration);

  assertThat(factory.called, is(true));
  assertThat(configHolder.cacheResources.getCacheLoaderWriter(), notNullValue());
  assertThat(configHolder.useEhcacheLoaderWriter, is(false));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:15,代码来源:ConfigurationMergerTest.java

示例8: getConfiguration

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
private MutableConfiguration<Long, String> getConfiguration(final boolean readThrough, final CacheLoader<Long, String> cacheLoader,
                                                            final boolean writeThrough, final CacheWriter<Long, String> cacheWriter) {
  MutableConfiguration<Long, String> config = new MutableConfiguration<>();
  config.setTypes(Long.class, String.class);
  config.setReadThrough(readThrough);
  config.setCacheLoaderFactory(() -> cacheLoader);
  config.setWriteThrough(writeThrough);
  config.setCacheWriterFactory(() -> cacheWriter);
  return config;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:11,代码来源:LoaderWriterConfigTest.java

示例9: onBeforeEachTest

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
 * Establish the {@link javax.cache.CacheManager} and {@link Cache} for a test.
 */
@Before
public void onBeforeEachTest() throws IOException {
  //establish and open a CacheLoaderServer to handle cache
  //cache loading requests from a CacheLoaderClient
  recordingCacheLoader = new RecordingCacheLoader<String>();
  cacheLoaderServer = new CacheLoaderServer<String, String>(10000, recordingCacheLoader);
  cacheLoaderServer.open();

  // establish and open a CacheWriterServer to handle cache
  // cache loading requests from a CacheWriterClient
  recordingCacheWriter = new RecordingCacheWriter<>();
  cacheWriterServer = new CacheWriterServer<>(10001, recordingCacheWriter);
  cacheWriterServer.open();

  //establish the CacheManager for the tests
  cacheManager = Caching.getCachingProvider().getCacheManager();

  //establish a CacheLoaderClient that a Cache can use for loading entries
  //(via the CacheLoaderServer)
  CacheLoaderClient<String, String> cacheLoader =
      new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());

  // establish a CacheWriterClient that a Cache can use for writing/deleting entries
  // (via the CacheWriterServer)
  CacheWriterClient<String, String> cacheWriter = new CacheWriterClient<>(cacheWriterServer.getInetAddress(),
      cacheWriterServer.getPort());

  //establish a Cache Configuration that uses a CacheLoader and Read-Through
  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class);
  configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
  configuration.setReadThrough(true);
  configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(cacheWriter));
  configuration.setWriteThrough(true);

  //configure the cache
  cacheManager.createCache("cache-loader-writer-test", configuration);
  cache = cacheManager.getCache("cache-loader-writer-test", String.class, String.class);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:43,代码来源:CacheLoaderWriterTest.java

示例10: onBeforeEachTest

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
 * Establish the {@link javax.cache.CacheManager} and {@link javax.cache.Cache} for a test.
 */
@Before
public void onBeforeEachTest() throws IOException {
  //establish and open a CacheLoaderServer to handle cache
  //cache loading requests from a CacheLoaderClient
  cacheLoaderServer = new CacheLoaderServer<String, String>(10000);
  cacheLoaderServer.open();

  //establish the CacheManager for the tests
  cacheManager = Caching.getCachingProvider().getCacheManager();

  //establish a CacheLoaderClient that a Cache can use for loading entries
  //(via the CacheLoaderServer)
  CacheLoaderClient<String, String> cacheLoader =
      new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());

  //establish a Cache Configuration that uses a CacheLoader, Read-Through and Expiry
  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class);
  configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
  configuration.setReadThrough(true);
  configuration.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnAccessPolicy.class));

  //configure the cache
  cacheManager.createCache("cache-loader-test", configuration);
  cache = cacheManager.getCache("cache-loader-test", String.class, String.class);
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:30,代码来源:CacheLoaderWithExpiryTest.java

示例11: invokeGetValueWithReadThroughForNonExistentEntryShouldCallGetExpiryForCreatedEntry

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeGetValueWithReadThroughForNonExistentEntryShouldCallGetExpiryForCreatedEntry() throws IOException {

  //establish and open a CacheLoaderServer to handle cache
  //cache loading requests from a CacheLoaderClient

  // this cacheLoader just returns the key as the value.
  RecordingCacheLoader<Integer> recordingCacheLoader = new RecordingCacheLoader<>();
  try (CacheLoaderServer<Integer, Integer> cacheLoaderServer = new CacheLoaderServer<>(10000, recordingCacheLoader)) {
    cacheLoaderServer.open();

    //establish a CacheLoaderClient that a Cache can use for loading entries
    //(via the CacheLoaderServer)
    CacheLoaderClient<Integer, Integer> cacheLoader =
        new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());

    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
    expiryPolicyServer.setExpiryPolicy(expiryPolicy);

    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient));
    config.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
    config.setReadThrough(true);
    Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);

    final Integer key = 123;
    final Integer recordingCacheLoaderValue = key;

    // verify create when read through is enabled and entry was non-existent in cache.
    Integer resultValue = cache.invoke(key, new GetEntryProcessor<Integer, Integer>());

    assertEquals(recordingCacheLoaderValue, resultValue);
    assertTrue(recordingCacheLoader.hasLoaded(key));

    assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(1));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
    closeTestCache();
  }
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:41,代码来源:CacheExpiryTest.java

示例12: testInvoke

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testInvoke()
{
    final CacheLoader<String, Integer> cacheLoader = new CacheLoader<String, Integer>()
    {
        @Override
        public Integer load(String key)
            throws CacheLoaderException
        {
            return Integer.valueOf(key);
        }

        @Override
        public Map<String, Integer> loadAll(Iterable<? extends String> keys)
            throws CacheLoaderException
        {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };

    final EntryProcessor<String, Integer, Boolean> entryProcessor = new EntryProcessor<String, Integer, Boolean>()
    {
        @Override
        public Boolean process(MutableEntry<String, Integer> entry, Object... arguments)
            throws EntryProcessorException
        {
            assertTrue(entry.exists());
            assertEquals(Integer.valueOf(1), entry.getValue());
            entry.setValue(2);
            assertEquals(Integer.valueOf(2), entry.getValue());
            entry.remove();
            assertFalse(entry.exists());

            return Boolean.TRUE;
        }
    };

    MutableConfiguration<String, Integer> custom = new MutableConfiguration<>(configuration);

    custom.setReadThrough(true);
    custom.setCacheLoaderFactory
    (
        new Factory<CacheLoader<String, Integer>>()
        {
            @Override
            public CacheLoader<String, Integer> create()
            {
                return cacheLoader;
            }
        }
    );

    Cache<String, Integer> invokingCache = cacheManager.createCache("invokingCache", custom);

    assertTrue(invokingCache.invoke("1", entryProcessor));
    assertFalse(invokingCache.containsKey("1"));
}
 
开发者ID:ocafebabe,项目名称:guava-jcache,代码行数:58,代码来源:GuavaCacheTest.java

示例13: invokeAllReadThroughEnabledGetOnNonExistentEntry

import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void invokeAllReadThroughEnabledGetOnNonExistentEntry() throws IOException {
  //establish and open a CacheLoaderServer to handle cache
  //cache loading requests from a CacheLoaderClient

  // this cacheLoader just returns the key as the value.
  RecordingCacheLoader<Integer> recordingCacheLoader = new RecordingCacheLoader<>();
  try (CacheLoaderServer<Integer, Integer> cacheLoaderServer = new CacheLoaderServer<>(10000, recordingCacheLoader)) {
    cacheLoaderServer.open();

    //establish a CacheLoaderClient that a Cache can use for loading entries
    //(via the CacheLoaderServer)
    CacheLoaderClient<Integer, Integer> cacheLoader =
        new CacheLoaderClient<>(cacheLoaderServer.getInetAddress(), cacheLoaderServer.getPort());

    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
    expiryPolicyServer.setExpiryPolicy(expiryPolicy);

    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient));
    config.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
    config.setReadThrough(true);

    Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);

    final Integer INITIAL_KEY = 123;
    final Integer MAX_KEY_VALUE = INITIAL_KEY + 4;

    // set keys to read through
    Set<Integer> keys = new HashSet<>();
    for (int key = INITIAL_KEY; key <= MAX_KEY_VALUE; key++) {
      keys.add(key);
    }

    // verify read-through of getValue of non-existent entries
    cache.invokeAll(keys, new GetEntryProcessor<Integer, Integer>());

    assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(keys.size()));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
    expiryPolicy.resetCount();
    closeTestCache();
  }
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:45,代码来源:CacheExpiryTest.java


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