/** See {@link MutableConfiguration#setCacheWriterFactory}. */ public void setCacheWriterFactory(Factory<? extends CacheWriter<? super K, ? super V>> factory) { delegate.setCacheWriterFactory(factory); }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setCacheWriterFactory( Factory<? extends CacheWriter<? super K, ? super V>> factory) { super.setCacheWriterFactory(factory); return this; }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); CachingProvider provider = Caching.getCachingProvider(); cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-loader-writer-107.xml").toURI(), getClass().getClassLoader()); testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>() .setReadThrough(true) .setWriteThrough(true) .setCacheLoaderFactory(() -> cacheLoader) .setCacheWriterFactory(() -> cacheWriter) .setTypes(Number.class, CharSequence.class)); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); CachingProvider provider = Caching.getCachingProvider(); cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-loader-writer-107-load-atomics.xml").toURI(), getClass().getClassLoader()); testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>() .setReadThrough(true) .setWriteThrough(true) .setCacheLoaderFactory(() -> cacheLoader) .setCacheWriterFactory(() -> cacheWriter) .setTypes(Number.class, CharSequence.class)); }
@Test public void jsr107WriterGetsRegistered() { MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); CacheWriter<Object, Object> mock = mock(CacheWriter.class); RecordingFactory<CacheWriter<Object, Object>> factory = factoryOf(mock); configuration.setWriteThrough(true).setCacheWriterFactory(factory); merger.mergeConfigurations("cache", configuration); assertThat(factory.called, is(true)); verify(cacheLoaderWriterFactory).registerJsr107Loader(eq("cache"), ArgumentMatchers.<CacheLoaderWriter<Object, Object>>isNotNull()); }
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; } }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setCacheWriterFactory( Factory<? extends CacheWriter<? super K, ? super V>> factory) { super.setCacheWriterFactory(factory); return this; }
/** See {@link MutableConfiguration#setCacheWriterFactory}. */ public void setCacheWriterFactory(Factory<? extends CacheWriter<? super K, ? super V>> factory) { delegate.setCacheWriterFactory(factory); }
@SuppressWarnings("unchecked") Factory<? extends CacheWriter<Key, Entry>> f = newInstance(contextClassLoader, writer, Factory.class); configuration.setCacheWriterFactory(f);
@SuppressWarnings("unchecked") Factory<? extends CacheWriter<Key, Entry>> f = newInstance(contextClassLoader, writer, Factory.class); configuration.setCacheWriterFactory(f);
private <T> MutableConfiguration<String, T> configure(final MutableConfiguration<String, T> configuration, final OAuth2Options opts) { ofNullable(opts.getJcacheLoader()) .map(n -> lookup(CacheLoader.class, n)) .ifPresent(l -> configuration.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<CacheLoader<String, T>>(l))); ofNullable(opts.getJcacheWriter()) .map(n -> lookup(CacheWriter.class, n)) .ifPresent(w -> configuration.setCacheWriterFactory(new FactoryBuilder.SingletonFactory<CacheWriter<String, T>>(w))); return configuration .setStoreByValue(opts.isJcacheStoreValue()) .setStatisticsEnabled(opts.isJcacheStatistics()) .setManagementEnabled(opts.isJcacheJmx()); }
configuration.setCacheWriterFactory(new FactoryBuilder.ClassFactory<CacheWriter<? super PageKey, ? super Page>>(properties.getProperty("cache-writer-factory")));
private 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()); mutableConfiguration.setWriteThrough(configuration.isWriteThrough()); return mutableConfiguration; } }
)) .setCacheWriterFactory(FactoryBuilder.factoryOf( new UserCacheWriter(userDao) ))
configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(theCacheWriter)); configuration.setWriteThrough(true);
/** * 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); }
configuration.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader)); configuration.setReadThrough(true); configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(cacheWriter)); configuration.setWriteThrough(true);
rawConfig2.setCacheWriterFactory(FactoryBuilder.factoryOf(RecordingCacheWriter.class)); rawConfig2.hashCode(); assertFalse(rawConfig1.equals(rawConfig2)); assertFalse(rawConfig2.equals(rawConfig1)); rawConfig1.setCacheWriterFactory(rawConfig2.getCacheWriterFactory()); assertEquals(rawConfig1, rawConfig2); rawConfig2.setCacheWriterFactory(FactoryBuilder.factoryOf(FailingCacheWriter.class)); rawConfig2.hashCode(); assertFalse(rawConfig2.equals(rawConfig1));