Java Code Examples for javax.cache.expiry.EternalExpiryPolicy#factoryOf()

The following examples show how to use javax.cache.expiry.EternalExpiryPolicy#factoryOf() . 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * @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 vote down vote up
/** 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: SerializableEntityCache.java    From requery with Apache License 2.0 5 votes vote down vote up
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 5
Source File: JCSConfiguration.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
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 6
Source File: Eh107CompleteConfiguration.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
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;
}