private void setupExpiryPolicy() {
    if (cache2kConfiguration.getExpiryPolicy() != null) {
      org.cache2k.expiry.ExpiryPolicy<K, V> ep0;
      try {
        ep0 = cache2kConfiguration.getExpiryPolicy().supply(manager.getCache2kManager());
      } catch (Exception ex) {
        throw new CacheException("couldn't initialize expiry policy", ex);
      }
      final org.cache2k.expiry.ExpiryPolicy<K, V> ep = ep0;
      cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(
        new org.cache2k.expiry.ExpiryPolicy<K, V>() {
        @Override
        public long calculateExpiryTime(final K key, final V value, final long loadTime, final CacheEntry<K, V> oldEntry) {
          if (value == null) {
            return NO_CACHE;
          }
          return ep.calculateExpiryTime(key, value, loadTime, oldEntry);
        }
      }));
      return;
    }
    if (config.getExpiryPolicyFactory() != null) {
      expiryPolicy = config.getExpiryPolicyFactory().create();
    }
    if (expiryPolicy == null || expiryPolicy instanceof EternalExpiryPolicy) {
      cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(new org.cache2k.expiry.ExpiryPolicy<K, V>() {
        @Override
        public long calculateExpiryTime(final K key, final V value, final long loadTime, final CacheEntry<K, V> oldEntry) {
          if (value == null) {
            return NO_CACHE;
          }
          return ETERNAL;
        }
      }));
      return;
    }
    if (expiryPolicy instanceof ModifiedExpiryPolicy) {
      Duration d = expiryPolicy.getExpiryForCreation();
      final long _millisDuration = d.getTimeUnit().toMillis(d.getDurationAmount());
      if (_millisDuration == 0) {
        cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(new org.cache2k.expiry.ExpiryPolicy<K, V>() {
          @Override
          public long calculateExpiryTime(final K key, final V value, final long loadTime, final CacheEntry<K, V> oldEntry) {
            return NO_CACHE;
          }
        }));
        return;
      }
      cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(new org.cache2k.expiry.ExpiryPolicy<K, V>() {
        @Override
        public long calculateExpiryTime(final K key, final V value, final long loadTime, final CacheEntry<K, V> oldEntry) {
          if (value == null) {
            return NO_CACHE;
          }
          return loadTime + _millisDuration;
        }
      }));
      return;
    }
    if (expiryPolicy instanceof CreatedExpiryPolicy) {
      cache2kConfiguration.setEternal(true);
      Duration d = expiryPolicy.getExpiryForCreation();
      final long _millisDuration = d.getTimeUnit().toMillis(d.getDurationAmount());
      if (_millisDuration == 0) {
        cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(new org.cache2k.expiry.ExpiryPolicy<K, V>() {
          @Override
          public long calculateExpiryTime(final K key, final V value, final long loadTime, final CacheEntry<K, V> oldEntry) {
            return NO_CACHE;
          }
        }));
        return;
      }
      cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(new org.cache2k.expiry.ExpiryPolicy<K, V>() {
        @Override
        public long calculateExpiryTime(final K key, final V value, final long loadTime, final CacheEntry<K, V> oldEntry) {
          if (value == null) {
            return NO_CACHE;
          }
          if (oldEntry == null) {
            return loadTime + _millisDuration;
          } else {
            return NEUTRAL;
          }
        }
      }));
      return;
    }
    needsTouchyWrapper = true;
    cache2kConfiguration.setExpiryPolicy(new CustomizationReferenceSupplier<org.cache2k.expiry.ExpiryPolicy<K, V>>(new TouchyJCacheAdapter.ExpiryPolicyAdapter<K,V>(expiryPolicy)));
  }
private void setupExpiryPolicy ( ) { if ( cache2kConfiguration . getExpiryPolicy ( ) != null ) { org . cache2k . expiry . ExpiryPolicy < K , V > ep0 ; try { ep0 = cache2kConfiguration . getExpiryPolicy ( ) . supply ( manager . getCache2kManager ( ) ) ; } catch ( Exception ex ) { throw new CacheException ( "couldn't initialize expiry policy" , ex ) ; } final org . cache2k . expiry . ExpiryPolicy < K , V > ep = ep0 ; cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new org . cache2k . expiry . ExpiryPolicy < K , V > ( ) { @ Override public long calculateExpiryTime ( final K key , final V value , final long loadTime , final CacheEntry < K , V > oldEntry ) { if ( value == null ) { return NO_CACHE ; } return ep . calculateExpiryTime ( key , value , loadTime , oldEntry ) ; } } ) ) ; return ; } if ( config . getExpiryPolicyFactory ( ) != null ) { expiryPolicy = config . getExpiryPolicyFactory ( ) . create ( ) ; } if ( expiryPolicy == null || expiryPolicy instanceof EternalExpiryPolicy ) { cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new org . cache2k . expiry . ExpiryPolicy < K , V > ( ) { @ Override public long calculateExpiryTime ( final K key , final V value , final long loadTime , final CacheEntry < K , V > oldEntry ) { if ( value == null ) { return NO_CACHE ; } return ETERNAL ; } } ) ) ; return ; } if ( expiryPolicy instanceof ModifiedExpiryPolicy ) { Duration d = expiryPolicy . getExpiryForCreation ( ) ; final long _millisDuration = d . getTimeUnit ( ) . toMillis ( d . getDurationAmount ( ) ) ; if ( _millisDuration == 0 ) { cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new org . cache2k . expiry . ExpiryPolicy < K , V > ( ) { @ Override public long calculateExpiryTime ( final K key , final V value , final long loadTime , final CacheEntry < K , V > oldEntry ) { return NO_CACHE ; } } ) ) ; return ; } cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new org . cache2k . expiry . ExpiryPolicy < K , V > ( ) { @ Override public long calculateExpiryTime ( final K key , final V value , final long loadTime , final CacheEntry < K , V > oldEntry ) { if ( value == null ) { return NO_CACHE ; } return loadTime + _millisDuration ; } } ) ) ; return ; } if ( expiryPolicy instanceof CreatedExpiryPolicy ) { cache2kConfiguration . setEternal ( true ) ; Duration d = expiryPolicy . getExpiryForCreation ( ) ; final long _millisDuration = d . getTimeUnit ( ) . toMillis ( d . getDurationAmount ( ) ) ; if ( _millisDuration == 0 ) { cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new org . cache2k . expiry . ExpiryPolicy < K , V > ( ) { @ Override public long calculateExpiryTime ( final K key , final V value , final long loadTime , final CacheEntry < K , V > oldEntry ) { return NO_CACHE ; } } ) ) ; return ; } cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new org . cache2k . expiry . ExpiryPolicy < K , V > ( ) { @ Override public long calculateExpiryTime ( final K key , final V value , final long loadTime , final CacheEntry < K , V > oldEntry ) { if ( value == null ) { return NO_CACHE ; } if ( oldEntry == null ) { return loadTime + _millisDuration ; } else { return NEUTRAL ; } } } ) ) ; return ; } needsTouchyWrapper = true ; cache2kConfiguration . setExpiryPolicy ( new CustomizationReferenceSupplier < org . cache2k . expiry . ExpiryPolicy < K , V > > ( new TouchyJCacheAdapter . ExpiryPolicyAdapter < K , V > ( expiryPolicy ) ) ) ; }
Register a expiry policy to cache2k.

<p>JSR107 requires that null values are deleted from the cache. We register an expiry policy
to cache2k to provide this behavior.