net.sf.ehcache
Class Element
public final
class
Element
extends Object
implements Serializable, Cloneable
A Cache Element, consisting of a key, value and attributes.
From ehcache-1.2, Elements can have keys and values that are Serializable or Objects. To preserve backward
compatibility, special accessor methods for Object keys and values are provided:
getObjectKey and
getObjectValue. If placing Objects in ehcace, developers must use the new getObject... methods to
avoid CacheExceptions. The get... methods are reserved for Serializable keys and values.
Version: $Id: Element.java 52 2006-04-24 14:50:03Z gregluck $
Author: Greg Luck
UNKNOWN: SerializableHasSerializationMethods
Constructor Summary |
| Element(Serializable key, Serializable value, long version)
A full constructor.
|
| Element(Object key, Object value, long version)
A full constructor.
|
| Element(Serializable key, Serializable value)
Constructor.
|
| Element(Object key, Object value)
Constructor.
|
Method Summary |
Object | clone()
Clones an Element. |
boolean | equals(Object object)
Equals comparison with another element, based on the key. |
long | getCreationTime()
Gets the creationTime attribute of the ElementAttributes object.
|
long | getHitCount()
Gets the hit count on this element. |
Serializable | getKey()
Gets the key attribute of the Element object.
|
long | getLastAccessTime()
Gets the last access time.
|
long | getNextToLastAccessTime()
Gets the next to last access time. |
Object | getObjectKey()
Gets the key attribute of the Element object.
|
Object | getObjectValue()
Gets the value attribute of the Element object as an Object.
|
long | getSerializedSize()
The size of this object in serialized form. |
Serializable | getValue()
Gets the value attribute of the Element object.
|
long | getVersion()
Gets the version attribute of the ElementAttributes object.
|
int | hashCode()
Gets the hascode, based on the key. |
boolean | isKeySerializable()
Whether the element's key may be Serialized.
|
boolean | isSerializable()
Whether the element may be Serialized.
|
void | resetAccessStatistics()
Resets the hit count to 0 and the last access time to 0. |
void | setCreateTime()
Sets the creationTime attribute of the ElementAttributes object. |
void | setVersion(long version)
Sets the version attribute of the ElementAttributes object.
|
String | toString()
Returns a String representation of the Element. |
void | updateAccessStatistics()
Sets the last access time to now. |
public Element(Serializable key, Serializable value, long version)
A full constructor.
Creation time is set to the current time. Last Access Time and Previous To Last Access Time
are not set.
Since: .4
public Element(Object key, Object value, long version)
A full constructor.
Creation time is set to the current time. Last Access Time and Previous To Last Access Time
are not set.
Since: 1.2
public Element(Serializable key, Serializable value)
Constructor.
Parameters: key value
public Element(Object key, Object value)
Constructor.
Parameters: key value
Since: 1.2
public final Object clone()
Clones an Element. A completely new object is created, with no common references with the
existing one.
This method will not work unless the Object is Serializable
Warning: This can be very slow on large object graphs. If you use this method
you should write a performance test to verify suitability.
Returns: a new Element, with exactly the same field values as the one it was cloned from.
Throws: CloneNotSupportedException
public final boolean equals(Object object)
Equals comparison with another element, based on the key.
public final long getCreationTime()
Gets the creationTime attribute of the ElementAttributes object.
Returns: The creationTime value
public final long getHitCount()
Gets the hit count on this element.
public final Serializable getKey()
Gets the key attribute of the Element object.
Returns: The key value. If the key is not Serializable, null is returned and an info log message emitted
See Also: getObjectKey
public final long getLastAccessTime()
Gets the last access time.
Access means a get. So a newly created
Element
will have a last access time equal to its create time.
final long getNextToLastAccessTime()
Gets the next to last access time. This is package protected as it should
not be used outside internal Cache housekeeping.
See Also: getLastAccessTime
public final Object getObjectKey()
Gets the key attribute of the Element object.
This method is provided for those wishing to use ehcache as a memory only cache
and enables retrieval of non-Serializable values from elements.
Returns: The key as an Object. i.e no restriction is placed on it
See Also: getKey
public final Object getObjectValue()
Gets the value attribute of the Element object as an Object.
This method is provided for those wishing to use ehcache as a memory only cache
and enables retrieval of non-Serializable values from elements.
Returns: The value as an Object. i.e no restriction is placed on it
Since: 1.2
See Also: getValue
public final long getSerializedSize()
The size of this object in serialized form. This is not the same
thing as the memory size, which is JVM dependent. Relative values should be meaningful,
however.
Warning: This method can be
very slow for values which contain large object graphs.
Returns: The serialized size in bytes
public final Serializable getValue()
Gets the value attribute of the Element object.
Returns: The value which must be Serializable. If not use Element. If the value is not Serializable, null is returned and an info log message emitted
See Also: getObjectValue
public final long getVersion()
Gets the version attribute of the ElementAttributes object.
Returns: The version value
public final int hashCode()
Gets the hascode, based on the key.
public final boolean isKeySerializable()
Whether the element's key may be Serialized.
While Element implements Serializable, it is possible to create non Serializable elements and/or
non Serializable keys for use in MemoryStores.
This method checks that an instance of an Element's key really is Serializable
and will not throw a NonSerializableException if Serialized.
Returns: true if the element's key is Serializable
Since: 1.2
public final boolean isSerializable()
Whether the element may be Serialized.
While Element implements Serializable, it is possible to create non Serializable elements
for use in MemoryStores. This method checks that an instance of Element really is Serializable
and will not throw a NonSerializableException if Serialized.
Returns: true if the element is Serializable
Since: 1.2
public final void resetAccessStatistics()
Resets the hit count to 0 and the last access time to 0.
public final void setCreateTime()
Sets the creationTime attribute of the ElementAttributes object.
public final void setVersion(long version)
Sets the version attribute of the ElementAttributes object.
Parameters: version The new version value
public final String toString()
Returns a String representation of the
Element.
public final void updateAccessStatistics()
Sets the last access time to now.