java.lang.Object
edu.iu.IuCachedValue<V>
- Type Parameters:
V
- value type
Holds a single value by
SoftReference
with timed expiration.
A cached value could be cleared by the garbage collector in order to prevent
OutOfMemoryError
due to insufficient heap space.
-
Constructor Summary
ConstructorsConstructorDescriptionIuCachedValue
(V value, Duration timeToLive, UnsafeRunnable onExpire) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Invalidates the cached value, invokes the onExpire thunk, and clears all related references and resource.boolean
get()
Gets the cached value.boolean
Determines if an object is equal to the referent.int
hashCode()
boolean
isValid()
Determines whether or not the cached value is still valid.
-
Constructor Details
-
IuCachedValue
Constructor.- Parameters:
value
- valuetimeToLive
- maximum length of time for the cached value to remain validonExpire
- thunk to invoke when the reference expires; should execute quickly, i.e., to remove a map entry relative the provided key
-
-
Method Details
-
get
Gets the cached value.- Returns:
- cached value; may be null if the cached value is null, the reference was cleared by the garbage collector, or the expiration time is in the past.
-
isValid
public boolean isValid()Determines whether or not the cached value is still valid.- Returns:
- true if the reference is still valid; false if it has been cleared by the garbage collection or the expiration time is in the past.
-
has
Determines if an object is equal to the referent.- Parameters:
o
- object- Returns:
- true if the reference is still
valid
and the referent is equal to the object.
-
clear
public void clear()Invalidates the cached value, invokes the onExpire thunk, and clears all related references and resource.This method has no effect if invoked on an invalid reference.
-
hashCode
public int hashCode() -
equals
-