org.weborganic.bastille.cache.util
Class SoftCacheableString
java.lang.Object
org.weborganic.bastille.cache.util.SoftCacheableString
- All Implemented Interfaces:
- Serializable
public final class SoftCacheableString
- extends Object
- implements Serializable
A simple wrapper around a string optimised for caching.
Objects maintain a transient SoftReference
to the string, ensuring that the string will only be removed
if there is a risk of an OutOfMemoryError
.
The object keeps a strong reference to a gzipped byte array, ensuring that the memory footprint is minimal when
the soft reference is removed and the serialization process is optimal.
This class is useful for strings which are sufficiently large with a low entropy so that their gzipped
representation will be significantly smaller than their string value.
- See Also:
- Serialized Form
SoftCacheableString
public SoftCacheableString(String data)
- Creates a new cached string.
- Parameters:
data
- the string to store
- Throws:
NullPointerException
- If the data is null
get
public String get()
- Returns:
- the string value.
toString
public String toString()
- Overrides:
toString
in class Object