javax.cache.expiry.EternalExpiryPolicy Java Examples
The following examples show how to use
javax.cache.expiry.EternalExpiryPolicy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Builder.java From triava with Apache License 2.0 | 6 votes |
/** * Sets the ExpiryPolicyFactory. It will overwrite any values set before via {@link #setMaxIdleTime(int, TimeUnit)}. * @param factory The factory * @return This Builder */ public Builder<K,V> setExpiryPolicyFactory(Factory<? extends ExpiryPolicy> factory) { if (expiryPolicyFactory == null) { this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); } else { @SuppressWarnings("unchecked") Factory<ExpiryPolicy> factoryCasted = (Factory<ExpiryPolicy>) factory; this.expiryPolicyFactory = (factoryCasted); } return this; }
Example #2
Source File: IgniteCacheExpiryPolicyAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testEternal() throws Exception { factory = EternalExpiryPolicy.factoryOf(); ExpiryPolicy plc = factory.create(); assertTrue(plc.getExpiryForCreation().isEternal()); assertNull(plc.getExpiryForUpdate()); assertNull(plc.getExpiryForAccess()); startGrids(); for (final Integer key : keys()) { log.info("Test eternalPolicy, key: " + key); eternal(key); } }
Example #3
Source File: TypesafeConfigurator.java From caffeine with Apache License 2.0 | 6 votes |
/** Adds the JCache specification's lazy expiration settings. */ public void addLazyExpiration() { Duration creation = getDurationFor("policy.lazy-expiration.creation"); Duration update = getDurationFor("policy.lazy-expiration.update"); Duration access = getDurationFor("policy.lazy-expiration.access"); requireNonNull(creation, "policy.lazy-expiration.creation may not be null"); boolean eternal = Objects.equals(creation, Duration.ETERNAL) && Objects.equals(update, Duration.ETERNAL) && Objects.equals(access, Duration.ETERNAL); @SuppressWarnings("NullAway") Factory<? extends ExpiryPolicy> factory = eternal ? EternalExpiryPolicy.factoryOf() : FactoryBuilder.factoryOf(new JCacheExpiryPolicy(creation, update, access)); configuration.setExpiryPolicyFactory(factory); }
Example #4
Source File: ShiroJCacheManagerAdapter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@VisibleForTesting <K, V> javax.cache.Cache<K, V> maybeCreateCache(final String name) { if (Objects.equals(ACTIVE_SESSION_CACHE_NAME, name)) { // shiro's session cache needs to never expire: // http://shiro.apache.org/session-management.html#ehcache-session-cache-configuration return cacheHelperProvider.get().maybeCreateCache(name, EternalExpiryPolicy.factoryOf()); } else { Time timeToLive = Optional.ofNullable(System.getProperty(name + ".timeToLive")) .map(Time::parse) .orElse(defaultTimeToLive.get()); return cacheHelperProvider.get().maybeCreateCache(name, CreatedExpiryPolicy.factoryOf(new Duration(timeToLive.getUnit(), timeToLive.getValue()))); } }
Example #5
Source File: SerializableEntityCache.java From requery with Apache License 2.0 | 5 votes |
public SerializableEntityCache(EntityModel model, CacheManager cacheManager) { if (cacheManager == null) { throw new IllegalArgumentException(); } this.model = model; this.cacheManager = cacheManager; this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); this.caches = new ClassMap<>(); }
Example #6
Source File: DiagnosticLogForPartitionStatesTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Tests that partitions validation is triggered and the corresponding message is logged * when eternal policy is explicitly used. * * @throws Exception If failed. */ @Test public void testShouldPrintMessageWhenEternalExpiryPolicyIsExplicitlyUsed() throws Exception { doTest( new CacheConfiguration<Integer, Integer>(CACHE_1) .setBackups(1) .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf()), true ); }
Example #7
Source File: Eh107XmlIntegrationTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void test107CacheCanReturnCompleteConfigurationWhenNonePassedIn() { CacheManager cacheManager = cachingProvider.getCacheManager(); Cache<Long, String> cache = cacheManager.createCache("cacheWithoutCompleteConfig", new Configuration<Long, String>() { private static final long serialVersionUID = 1L; @Override public Class<Long> getKeyType() { return Long.class; } @Override public Class<String> getValueType() { return String.class; } @Override public boolean isStoreByValue() { return true; } }); @SuppressWarnings("unchecked") CompleteConfiguration<Long, String> configuration = cache.getConfiguration(CompleteConfiguration.class); assertThat(configuration, notNullValue()); assertThat(configuration.isStoreByValue(), is(true)); // Respects defaults assertThat(configuration.getExpiryPolicyFactory(), equalTo(EternalExpiryPolicy.factoryOf())); }
Example #8
Source File: JCSConfiguration.java From commons-jcs with Apache License 2.0 | 5 votes |
public JCSConfiguration(final Configuration<K, V> configuration, final Class<K> keyType, final Class<V> valueType) { this.keyType = keyType; this.valueType = valueType; if (configuration instanceof CompleteConfiguration) { final CompleteConfiguration<K, V> cConfiguration = (CompleteConfiguration<K, V>) configuration; storeByValue = configuration.isStoreByValue(); readThrough = cConfiguration.isReadThrough(); writeThrough = cConfiguration.isWriteThrough(); statisticsEnabled = cConfiguration.isStatisticsEnabled(); managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); cacheEntryListenerConfigurations = new HashSet<>(); final Iterable<CacheEntryListenerConfiguration<K, V>> entryListenerConfigurations = cConfiguration .getCacheEntryListenerConfigurations(); if (entryListenerConfigurations != null) { for (final CacheEntryListenerConfiguration<K, V> kvCacheEntryListenerConfiguration : entryListenerConfigurations) { cacheEntryListenerConfigurations.add(kvCacheEntryListenerConfiguration); } } } else { expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); storeByValue = true; readThrough = false; writeThrough = false; statisticsEnabled = false; managementEnabled = false; cacheLoaderFactory = null; cacheWristerFactory = null; cacheEntryListenerConfigurations = new HashSet<>(); } }
Example #9
Source File: ShiroJCacheManagerAdapterTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Test public void defaultShiroActiveSessionCacheConfigurationTest() throws Exception { when(cacheHelper.maybeCreateCache(anyString(), confCaptor.capture())).thenReturn(null); underTest.maybeCreateCache(CachingSessionDAO.ACTIVE_SESSION_CACHE_NAME); assertThat(confCaptor.getValue(), is(EternalExpiryPolicy.factoryOf())); }
Example #10
Source File: CacheMvccOperationChecksTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception if failed. */ @Test public void testWithExpiryPolicyUnsupported() throws Exception { checkOperationUnsupported("withExpiryPolicy", m("withExpiryPolicy"), t(ExpiryPolicy.class), EternalExpiryPolicy.factoryOf().create()); }
Example #11
Source File: BlazingCacheCache.java From blazingcache with Apache License 2.0 | 4 votes |
public BlazingCacheCache(String cacheName, CacheClient client, CacheManager cacheManager, Serializer<K, String, String> keysSerializer, Serializer<V, InputStream, byte[]> valuesSerializer, boolean usefetch, Configuration<K, V> configuration) { this.cacheName = cacheName; this.cacheManager = cacheManager; this.client = client; this.keysSerializer = keysSerializer; this.valuesSerializer = valuesSerializer; this.valueType = configuration.getValueType(); this.keyType = configuration.getKeyType(); this.usefetch = usefetch; this.configurationMXBean = new BlazingCacheConfigurationMXBean<>(this); this.statisticsMXBean = new BlazingCacheStatisticsMXBean<>(this); this.storeByReference = !configuration.isStoreByValue(); if (configuration instanceof CompleteConfiguration) { this.configuration = new MutableConfiguration<>((CompleteConfiguration<K, V>) configuration); CompleteConfiguration<K, V> cc = (CompleteConfiguration<K, V>) configuration; if (cc.getExpiryPolicyFactory() == null) { throw new IllegalArgumentException("ExpiryPolicyFactory cannot be null"); } else { ExpiryPolicy _policy = cc.getExpiryPolicyFactory().create();; if (_policy == null) { throw new IllegalArgumentException("ExpiryPolicy cannot be null"); } if (_policy instanceof EternalExpiryPolicy) { this.policy = null; // shortcut for the most common case } else { this.policy = _policy; } } if (cc.getCacheLoaderFactory() != null) { cacheLoader = (CacheLoader) cc.getCacheLoaderFactory().create(); } else { cacheLoader = null; } if (cc.getCacheWriterFactory() != null) { cacheWriter = (CacheWriter<K, V>) cc.getCacheWriterFactory().create(); } else { cacheWriter = null; } isReadThrough = cc.isReadThrough(); isWriteThrough = cc.isWriteThrough(); needPreviuosValueForListeners = policy != null; if (cc.getCacheEntryListenerConfigurations() != null) { for (CacheEntryListenerConfiguration<K, V> listenerConfig : cc.getCacheEntryListenerConfigurations()) { configureListener(listenerConfig); } } } else { this.configuration = new MutableConfiguration<K, V>() .setTypes(configuration.getKeyType(), configuration.getValueType()) .setStoreByValue(configuration.isStoreByValue()); this.policy = null; // means "eternal" cacheLoader = null; needPreviuosValueForListeners = false; cacheWriter = null; isReadThrough = false; isWriteThrough = false; } if (isReadThrough && cacheLoader == null) { throw new IllegalArgumentException("cache isReadThrough=" + isReadThrough + " cacheLoader=" + cacheLoader); } if (isWriteThrough && cacheWriter == null) { throw new IllegalArgumentException("cache isWriteThrough=" + isWriteThrough + " cacheWriter=" + cacheWriter); } if (this.configuration.isManagementEnabled()) { setManagementEnabled(true); } if (this.configuration.isStatisticsEnabled()) { setStatisticsEnabled(true); } }
Example #12
Source File: Eh107CompleteConfiguration.java From ehcache3 with Apache License 2.0 | 4 votes |
public Eh107CompleteConfiguration(Configuration<K, V> config, final CacheConfiguration<K, V> ehcacheConfig, boolean useEhcacheExpiry, boolean useEhcacheLoaderWriter) { this.ehcacheConfig = ehcacheConfig; this.keyType = config.getKeyType(); this.valueType = config.getValueType(); this.isStoreByValue = isStoreByValue(config, ehcacheConfig); Factory<ExpiryPolicy> tempExpiryPolicyFactory = EternalExpiryPolicy.factoryOf(); if (config instanceof CompleteConfiguration) { CompleteConfiguration<K, V> completeConfig = (CompleteConfiguration<K, V>) config; this.isReadThrough = completeConfig.isReadThrough(); this.isWriteThrough = completeConfig.isWriteThrough(); this.isStatisticsEnabled = completeConfig.isStatisticsEnabled(); this.isManagementEnabled = completeConfig.isManagementEnabled(); if (useEhcacheLoaderWriter) { this.cacheLoaderFactory = createThrowingFactory(); this.cacheWriterFactory = createThrowingFactory(); } else { this.cacheLoaderFactory = completeConfig.getCacheLoaderFactory(); this.cacheWriterFactory = completeConfig.getCacheWriterFactory(); } tempExpiryPolicyFactory = completeConfig.getExpiryPolicyFactory(); for (CacheEntryListenerConfiguration<K, V> listenerConfig : completeConfig.getCacheEntryListenerConfigurations()) { cacheEntryListenerConfigs.add(listenerConfig); } } else { this.isReadThrough = false; this.isWriteThrough = false; this.isStatisticsEnabled = false; this.isManagementEnabled = false; this.cacheLoaderFactory = null; this.cacheWriterFactory = null; } if (useEhcacheExpiry) { tempExpiryPolicyFactory = createThrowingFactory(); } this.expiryPolicyFactory = tempExpiryPolicyFactory; }