本文整理汇总了Java中javax.cache.configuration.MutableConfiguration.setWriteThrough方法的典型用法代码示例。如果您正苦于以下问题:Java MutableConfiguration.setWriteThrough方法的具体用法?Java MutableConfiguration.setWriteThrough怎么用?Java MutableConfiguration.setWriteThrough使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.cache.configuration.MutableConfiguration
的用法示例。
在下文中一共展示了MutableConfiguration.setWriteThrough方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBeforeEachTest
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Configure write-through before each test.
*/
@Before
public void onBeforeEachTest() throws IOException {
// establish and open a CacheWriterServer to handle cache
// cache loading requests from a CacheWriterClient
cacheWriter = new RecordingCacheWriter<>();
cacheWriterServer = new CacheWriterServer<>(10000, cacheWriter);
cacheWriterServer.open();
// establish the CacheManager for the tests
cacheManager = Caching.getCachingProvider().getCacheManager();
// establish a CacheWriterClient that a Cache can use for writing/deleting entries
// (via the CacheWriterServer)
CacheWriterClient<Integer, String> theCacheWriter = new CacheWriterClient<>(cacheWriterServer.getInetAddress(),
cacheWriterServer.getPort());
MutableConfiguration<Integer, String> configuration = new MutableConfiguration<>();
configuration.setTypes(Integer.class, String.class);
configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(theCacheWriter));
configuration.setWriteThrough(true);
getCacheManager().createCache("cache-writer-test", configuration);
cache = getCacheManager().getCache("cache-writer-test", Integer.class, String.class);
}
示例2: testCreateWriteThroughCacheWithInvalidConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void testCreateWriteThroughCacheWithInvalidConfiguration()
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setWriteThrough(true);
cacheManager.createCache("cache", configuration);
}
示例3: setWriteThroughWithoutWriterFails
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void setWriteThroughWithoutWriterFails() {
MutableConfiguration<Long, String> config = new MutableConfiguration<>();
config.setTypes(Long.class, String.class);
config.setWriteThrough(true);
try {
merger.mergeConfigurations("cache", config);
fail("Expected exception as no CacheLoader factory is configured and read-through is enabled.");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("write-through"));
}
}
示例4: 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;
}
示例5: 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);
}