Expiry Policies
This is a legacy Apache Ignite documentationThe new documentation is hosted here: https://ignite.apache.org/docs/latest/
Expiry Policy specifies the amount of time that must pass before an entry is considered expired. Time can be counted from creation, last access, or modification time.
Your deployment's memory configuration will determine how the expiration policies function:
- In-Memory Mode (data is stored solely in RAM): expired entries are purged from RAM completely.
- Memory + Ignite persistence: expired entries are removed from both memory and disk tiers. Note that expiry policies will remove entries from the partition files on disk without freeing up space. The space will be reused to write subsequent entries.
- Memory + 3rd party persistence: expired entries are removed from the memory tier only (Ignite) and left untouched in the 3rd party persistence (RDBMS, NoSQL, and other databases).
- Memory + Swap: expired entries are removed from both RAM and swap files.
Expiry Policy can be configured using any of the predefined implementations of javax.cache.expiry.ExpiryPolicy:
| Class name | creation time | last access time | last update time |
|---|---|---|---|
CreatedExpiryPolicy | Used | ||
AccessedExpiryPolicy | Used | Used | |
ModifiedExpiryPolicy | Used | Used | |
TouchedExpiryPolicy | Used | Used | Used |
EternalExpiryPolicy |
Custom ExpiryPolicy implementations are also allowed.
Expiry Policy can be configured in CacheConfiguration. This policy will be used for all entries inside the cache.
cfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ZERO));<bean class="org.apache.ignite.configuration.CacheConfiguration">
...
<property name="expiryPolicyFactory">
<bean class="javax.cache.expiry.CreatedExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="MINUTES"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>Also, it is possible to change or set Expiry Policy for individual operations on the cache.
IgniteCache<Object, Object> cache = cache.withExpiryPolicy(
new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));This policy will be used for each operation invoked on the returned cache instance.
Eager TTL
Entries that are expired can be removed from cache either eagerly or when they are touched by different cache operations. If there is at least one cache configured with eager TTL enabled, Ignite will create a single thread to clean up expired entries in the background.
Eager TTL can be enabled or disabled via the CacheConfiguration.eagerTtl property (default value is true):
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="eagerTtl" value="true"/>
</bean>Updated over 1 year ago

