Class VersionedCacheEntry<T>
- java.lang.Object
-
- com.identityworksllc.iiq.common.cache.CacheEntry<T>
-
- com.identityworksllc.iiq.common.cache.VersionedCacheEntry<T>
-
- Type Parameters:
T
- The type stored in this cache entry
- All Implemented Interfaces:
Serializable
,Supplier<Optional<T>>
public class VersionedCacheEntry<T> extends CacheEntry<T>
A plugin version aware extension ofCacheEntry
, which will consider itself expired whenever the plugin version has changed from the version at entry creation.Instances of this class are NOT Serializable, because it doesn’t make sense to serialize a plugin-versioned object.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description VersionedCacheEntry(CacheEntry<? extends T> entry)
Copy constructor for another cache entry.VersionedCacheEntry(T entryValue, long entryExpirationTimestampMillis)
Constructs a new VersionedCacheEntry expiring at the given epoch millisecond timestampVersionedCacheEntry(T entryValue, long futureTimeAmount, TimeUnit timeUnit)
Constructs a new VersionedCacheEntry expiring at the given time in the futureVersionedCacheEntry(T entryValue, Date entryExpiration)
Constructs a new VersionedCacheEntry expiring at the given Date
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
int
hashCode()
boolean
isExpired()
Marks this object expired if its time has elapsed or if the plugin version has changed since the cache entry was created.static <V> VersionedCacheEntry<V>
of(CacheEntry<? extends V> other)
Returns either the current object, if it is already a VersionedCacheEntry, or a newly constructed copy of it.-
Methods inherited from class com.identityworksllc.iiq.common.cache.CacheEntry
asStampedReference, computeIfExpired, get, getExpiration, getValue, toString
-
-
-
-
Constructor Detail
-
VersionedCacheEntry
public VersionedCacheEntry(CacheEntry<? extends T> entry)
Copy constructor for another cache entry.If the other entry is a VersionedCacheEntry, its pluginVersion will also be copied. Otherwise, the current plugin version will be used.
This should be used with caution, because you can construct a versioned object that looks right, but is not.
- Parameters:
entry
- The entry to copy
-
VersionedCacheEntry
public VersionedCacheEntry(T entryValue, long futureTimeAmount, TimeUnit timeUnit)
Constructs a new VersionedCacheEntry expiring at the given time in the future- Parameters:
entryValue
- The value being cachedfutureTimeAmount
- The number of time units in the future to expire this entrytimeUnit
- The time unit (e.g., seconds) to calculate the expiration time
-
VersionedCacheEntry
public VersionedCacheEntry(T entryValue, Date entryExpiration)
Constructs a new VersionedCacheEntry expiring at the given Date- Parameters:
entryValue
- The value being cachedentryExpiration
- The
-
VersionedCacheEntry
public VersionedCacheEntry(T entryValue, long entryExpirationTimestampMillis)
Constructs a new VersionedCacheEntry expiring at the given epoch millisecond timestamp- Parameters:
entryValue
- The value being cachedentryExpirationTimestampMillis
- The epoch millisecond timestamp after which this entry is expired
-
-
Method Detail
-
of
public static <V> VersionedCacheEntry<V> of(CacheEntry<? extends V> other) throws IllegalArgumentException
Returns either the current object, if it is already a VersionedCacheEntry, or a newly constructed copy of it.- Type Parameters:
V
- The type of the object- Parameters:
other
- The other object to either return or copy- Returns:
- A non-null VersionedCacheObject
- Throws:
IllegalArgumentException
- if the input is null or otherwise invalid
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classCacheEntry<T>
- See Also:
Object.equals(Object)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classCacheEntry<T>
- See Also:
Object.hashCode()
-
isExpired
public boolean isExpired()
Marks this object expired if its time has elapsed or if the plugin version has changed since the cache entry was created.- Overrides:
isExpired
in classCacheEntry<T>
- Returns:
- True if this is expired
-
-