本文整理汇总了Java中javax.cache.expiry.EternalExpiryPolicy类的典型用法代码示例。如果您正苦于以下问题:Java EternalExpiryPolicy类的具体用法?Java EternalExpiryPolicy怎么用?Java EternalExpiryPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EternalExpiryPolicy类属于javax.cache.expiry包,在下文中一共展示了EternalExpiryPolicy类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
@Override
protected void setup(Settings settings, CacheManager cacheManager) {
cacheManager.createCache(STRING_LONG_CACHE, new MutableConfiguration()
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf())
.setStatisticsEnabled(true)
.setStoreByValue(true));
cacheManager.createCache(STRING_STRING_CACHE, new MutableConfiguration()
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf())
.setStatisticsEnabled(true)
.setStoreByValue(true));
cacheManager.createCache(LONG_STRING_CACHE, new MutableConfiguration()
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf())
.setStatisticsEnabled(true)
.setStoreByValue(true));
}
示例2: setExpiryPolicyFactory
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
/**
* 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;
}
示例3: testEternal
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
/**
* @throws Exception If failed.
*/
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);
}
}
示例4: validateConfiguration
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
private void validateConfiguration(CompleteConfiguration<?, ?> configuration)
{
if (configuration.isStoreByValue())
{
throw new UnsupportedOperationException("Store by value is not supported in Guava!");
}
if (configuration.getExpiryPolicyFactory() == null)
{
throw new NullPointerException("Expiry policy factory cannot be null!");
}
ExpiryPolicy expiryPolicy = configuration.getExpiryPolicyFactory().create();
if (!(expiryPolicy instanceof EternalExpiryPolicy)
&& !(expiryPolicy instanceof ModifiedExpiryPolicy)
&& !(expiryPolicy instanceof TouchedExpiryPolicy))
{
throw new UnsupportedOperationException("Invalid expiry policy configuration!");
}
if (configuration.isReadThrough() && configuration.getCacheLoaderFactory() == null)
{
throw new IllegalArgumentException("Invalid read through cache configuration!");
}
if (configuration.isWriteThrough() || configuration.getCacheWriterFactory() != null)
{
throw new UnsupportedOperationException("Invalid write through cache configuration!");
}
}
示例5: maybeCreateCache
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
@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())));
}
}
示例6: defaultShiroActiveSessionCacheConfigurationTest
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
@Test
public void defaultShiroActiveSessionCacheConfigurationTest() throws Exception {
ArgumentCaptor<Factory> confCaptor = ArgumentCaptor.forClass(Factory.class);
when(cacheHelper.maybeCreateCache(anyString(), confCaptor.capture())).thenReturn(null);
underTest.maybeCreateCache(CachingSessionDAO.ACTIVE_SESSION_CACHE_NAME);
assertThat(confCaptor.getValue(), is(EternalExpiryPolicy.factoryOf()));
}
示例7: SerializableEntityCache
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
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<>();
}
示例8: test107CacheCanReturnCompleteConfigurationWhenNonePassedIn
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
@Test
public void test107CacheCanReturnCompleteConfigurationWhenNonePassedIn() {
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<Long, String> cache = cacheManager.createCache("cacheWithoutCompleteConfig", new Configuration<Long, String>() {
@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()));
}
示例9: BlazingCacheCache
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
public BlazingCacheCache(String cacheName, CacheClient client, CacheManager cacheManager, Serializer<K, String> keysSerializer, Serializer<V, 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);
}
}
示例10: Eh107CompleteConfiguration
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
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;
}
示例11: createFactory
import javax.cache.expiry.EternalExpiryPolicy; //导入依赖的package包/类
public Factory<? extends ExpiryPolicy> createFactory( Long seconds ) {
return EternalExpiryPolicy.factoryOf();
}