javax.cache
Interface ExpiryPolicy<K,V>

Type Parameters:
K - the type of keys
V - the type of values
All Known Implementing Classes:
ExpiryPolicy.Accessed, ExpiryPolicy.Default, ExpiryPolicy.Modified

public interface ExpiryPolicy<K,V>

Defines functions to determine when cache entries will expire based on creation, access and modification operations.

Each of the functions return a Configuration.Duration that of which specifies the amount of time that must pass before a cache entry is considered expired. This Configuration.Duration is often called a "time-to-live", commonly abbreviated to simply "TTL".

Author:
Brian Oliver

Nested Class Summary
static class ExpiryPolicy.Accessed<K,V>
          A ExpiryPolicy that defines the expiry Configuration.Duration of a Cache Entry based on the last time it was accessed.
static class ExpiryPolicy.Default<K,V>
          The default ExpiryPolicy specifies that Cache Entries won't expire.
static class ExpiryPolicy.Modified<K,V>
          A ExpiryPolicy that defines the expiry Configuration.Duration of a Cache Entry based on the last time it was modified.
 
Method Summary
 Configuration.Duration getTTLForAccessedEntry(Cache.Entry<? extends K,? extends V> entry, Configuration.Duration duration)
          Gets the time-to-live before the accessed Cache.Entry is considered expired.
 Configuration.Duration getTTLForCreatedEntry(Cache.Entry<? extends K,? extends V> entry)
          Gets the time-to-live before the newly Cache.Entry is considered expired.
 Configuration.Duration getTTLForModifiedEntry(Cache.Entry<? extends K,? extends V> entry, Configuration.Duration duration)
          Gets the time-to-live before the modified Cache.Entry is considered expired.
 

Method Detail

getTTLForCreatedEntry

Configuration.Duration getTTLForCreatedEntry(Cache.Entry<? extends K,? extends V> entry)
Gets the time-to-live before the newly Cache.Entry is considered expired.

This method is called after a Cache.Entry is created, but before the said entry is added to a cache, to determine the Configuration.Duration before the said entry expires. If a Configuration.Duration.ZERO is returned the Cache.Entry is considered to be already expired and will not be added to the Cache.

Parameters:
entry - the cache entry that was created
Returns:
the duration until the entry expires

getTTLForAccessedEntry

Configuration.Duration getTTLForAccessedEntry(Cache.Entry<? extends K,? extends V> entry,
                                              Configuration.Duration duration)
Gets the time-to-live before the accessed Cache.Entry is considered expired.

This method is called after a Cache.Entry is accessed to determine the Configuration.Duration before the said entry expires in the future. If a Configuration.Duration.ZERO is returned the Cache.Entry will be considered expired for future access.

Parameters:
entry - the cache entry that was accessed
duration - the current Configuration.Duration before the entry expires
Returns:
the duration until the entry expires

getTTLForModifiedEntry

Configuration.Duration getTTLForModifiedEntry(Cache.Entry<? extends K,? extends V> entry,
                                              Configuration.Duration duration)
Gets the time-to-live before the modified Cache.Entry is considered expired.

This method is called after a Cache.Entry is modified to determine the Configuration.Duration before the updated entry expires. If a Configuration.Duration.ZERO is returned the Cache.Entry is considered already expired.

Parameters:
entry - the cache entry that was modified
duration - the current Configuration.Duration before the updated entry expires
Returns:
the duration until the entry expires


Copyright © 2013. All Rights Reserved.