Package org.jivesoftware.util
Class CacheableOptional<T extends Serializable>
java.lang.Object
org.jivesoftware.util.CacheableOptional<T>
- All Implemented Interfaces:
Serializable
,Cacheable
Some times it is desirable to store in a
Cache
the absence of a value.
Unfortunately, it's not possible to store a null
value in a clustered cache because of the underlying hazelcast
technology used for clustering. The obvious candidate would therefore be to store an Optional
object in the
cache instead - unfortunately an Optional is not serializable. This class therefore performs this functionality - an
optional value that is cacheable.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
static <T extends Serializable>
CacheableOptional<T>get()
int
Returns the approximate size of the Object in bytes.int
hashCode()
boolean
isAbsent()
boolean
static <T extends Serializable>
CacheableOptional<T>of
(T value) toString()
-
Method Details
-
of
-
from
-
get
-
isPresent
public boolean isPresent() -
isAbsent
public boolean isAbsent() -
toOptional
-
equals
-
hashCode
public int hashCode() -
toString
-
getCachedSize
Description copied from interface:Cacheable
Returns the approximate size of the Object in bytes. The size should be considered to be a best estimate of how much memory the Object occupies and may be based on empirical trials or dynamic calculations.- Specified by:
getCachedSize
in interfaceCacheable
- Returns:
- the size of the Object in bytes.
- Throws:
CannotCalculateSizeException
- if the size cannot be calculated
-