2

For example, I would like to configure the cache with the following two expiry policies:

  • TouchedExpiryPolicy
  • CreatedExpiryPolicy

The sample code is as below (Apache Ignite version 1.5.0.final):

public IgniteCache<String, Object> getOrCreateCache(String cacheName) {
    Ignite ignite = Ignition.ignite();

    CacheConfiguration<String, Object> cacheCfg = new CacheConfiguration<String, Object>(cacheName);
    cacheCfg.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 10)));
    cacheCfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 30)));

    IgniteCache<String, Object> igniteCache = ignite.getOrCreateCache(cacheCfg);
    return igniteCache;     
}

The problem is, however, that the second expiry policy will replace the first one. Wonder if there is any way I can configure the Ignite cache so that the cache will honour both expiry policies? Thank you.

By the way, in EhCache, I can achieve the same thing by configuring the cache the following way:

<cache name="my-cache-name" ...
    timeToIdleSeconds="10" timeToLiveSeconds="30"
    ...>        
</cache>

References:

Yuci
  • 27,235
  • 10
  • 114
  • 113

1 Answers1

4

Answering for general JCache ExpiryPolicy, maybe there are additional options in Apache Ignite.

The TouchedExpiryPolicy uses the same duration for creation and update.

You can set individual times, by subclassing the ExpiryPolicy.

Be careful about the logic implications. Setting 10 seconds expiry after access and 30 seconds after creation means for example:

  • Item is created, stays 30 seconds in the cache, if not accessed
  • Item is created, is accessed 5 seconds after creation, item expires 15 seconds after creation (10 seconds after access)

Probably you want to achieve something different. So the answer is: Mixing TTL and TTI isn't possible the way it is designed.

cruftex
  • 5,545
  • 2
  • 20
  • 36
  • In Ignite it's possible to set only one `ExpirePolicy` globally per cache as well. So all your suggestions look correct for me. – dmagda May 20 '16 at 06:37
  • The purpose of mixing TTL and TTI is to expire the cache whenever either of the criteria gets met, no matter which one first. – Yuci May 20 '16 at 09:06
  • @Yuci, I understand what you try to do. Probably many people want to mix the two concepts. But it is not designed that way. There is only one active duration when an item will expire, not two. I opened an issue for this in the JSR107 issue tracker to get some more opinions on this: https://github.com/jsr107/jsr107spec/issues/355. Maybe there is still another way in Ignite to achieve this. – cruftex May 20 '16 at 09:19