public class Element
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
getObjectKey()
and
getObjectValue()
. If placing Objects in ehcache, developers must use the new getObject... methods to
avoid CacheExceptions. The get... methods are reserved for Serializable keys and values.Modifier and Type | Field and Description |
---|---|
private boolean |
cacheDefaultLifespan |
private static boolean |
ELEMENT_VERSION_AUTO |
private ElementEvictionData |
elementEvictionData
Pluggable element eviction data instance
|
private static java.util.concurrent.atomic.AtomicLongFieldUpdater<Element> |
HIT_COUNT_UPDATER |
private long |
hitCount
The number of times the element was hit.
|
private long |
id |
private java.lang.Object |
key
the cache key.
|
private long |
lastUpdateTime
If there is an Element in the Cache and it is replaced with a new Element for the same key,
then both the version number and lastUpdateTime should be updated to reflect that.
|
private static org.slf4j.Logger |
LOG |
private static long |
NOT_SET_ID |
private static long |
serialVersionUID
serial version
Updated for version 1.2, 1.2.1 and 1.7
|
private int |
timeToIdle
The amount of time for the element to idle, in seconds.
|
private int |
timeToLive
The amount of time for the element to live, in seconds.
|
private java.lang.Object |
value
the value.
|
private long |
version
version of the element.
|
Constructor and Description |
---|
Element(java.lang.Object key,
java.lang.Object value)
Constructor.
|
Element(java.lang.Object key,
java.lang.Object value,
java.lang.Boolean eternal,
java.lang.Integer timeToIdleSeconds,
java.lang.Integer timeToLiveSeconds)
Constructor used by ehcache-server
|
Element(java.lang.Object key,
java.lang.Object value,
long version)
A full constructor.
|
Element(java.lang.Object key,
java.lang.Object value,
long version,
long creationTime,
long lastAccessTime,
long hitCount,
boolean cacheDefaultLifespan,
int timeToLive,
int timeToIdle,
long lastUpdateTime)
Constructor used by ElementData.
|
Element(java.lang.Object key,
java.lang.Object value,
long version,
long creationTime,
long lastAccessTime,
long lastUpdateTime,
long hitCount)
Constructor.
|
Element(java.lang.Object key,
java.lang.Object value,
long version,
long creationTime,
long lastAccessTime,
long nextToLastAccessTime,
long lastUpdateTime,
long hitCount)
Deprecated.
The
nextToLastAccessTime field is unused since
version 1.7, setting it will have no effect. Use
#Element(Object, Object, long, long, long, long, long)
instead |
Element(java.io.Serializable key,
java.io.Serializable value)
Constructor.
|
Element(java.io.Serializable key,
java.io.Serializable value,
long version)
A full constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clones an Element.
|
private static java.lang.Object |
deepCopy(java.lang.Object oldValue) |
boolean |
equals(java.lang.Object object)
Equals comparison with another element, based on the key.
|
long |
getCreationTime()
Gets the creationTime of the Element
|
ElementEvictionData |
getElementEvictionData()
Retrieves this element's eviction data instance.
|
long |
getExpirationTime()
Returns the expiration time based on time to live.
|
long |
getHitCount()
Gets the hit count on this element.
|
(package private) long |
getId()
Gets the element identifier (this field is used internally by ehcache)
|
java.io.Serializable |
getKey()
Deprecated.
Please use
getObjectKey() instead. |
long |
getLastAccessTime()
Gets the last access time.
|
long |
getLastUpdateTime()
If there is an Element in the Cache and it is replaced with a new Element for the same key,
then both the version number and lastUpdateTime should be updated to reflect that.
|
long |
getLatestOfCreationAndUpdateTime()
Calculates the latest of creation and update time
|
long |
getNextToLastAccessTime()
Deprecated.
The
nextToLastAccessTime field is unused since
version 1.7, retrieving it will return the lastAccessTime . Use #getLastAccessTime() instead. |
java.lang.Object |
getObjectKey()
Gets the key attribute of the Element object.
|
java.lang.Object |
getObjectValue()
Gets the value attribute of the Element object as an Object.
|
long |
getSerializedSize()
The size of this object in serialized form.
|
int |
getTimeToIdle() |
int |
getTimeToLive() |
java.io.Serializable |
getValue()
Deprecated.
Please use
getObjectValue() instead. |
long |
getVersion()
Gets the version attribute of the ElementAttributes object.
|
int |
hashCode()
Gets the hashcode, based on the key.
|
(package private) boolean |
hasId()
Determines if an Id has been set on this element
|
boolean |
isEternal() |
boolean |
isExpired()
An element is expired if the expiration time as given by
getExpirationTime() is in the past. |
boolean |
isExpired(CacheConfiguration config)
An element is expired if the expiration time as given by
getExpirationTime() is in the past. |
boolean |
isKeySerializable()
Whether the element's key may be Serialized.
|
boolean |
isLifespanSet()
Whether any combination of eternal, TTL or TTI has been set.
|
boolean |
isSerializable()
Whether the element may be Serialized.
|
private void |
readObject(java.io.ObjectInputStream in)
Custom serialization read logic
|
void |
resetAccessStatistics()
Resets the hit count to 0 and the last access time to now.
|
void |
setCreateTime()
Deprecated.
Resetting the creation time is not recommended as of version
1.7
|
void |
setElementEvictionData(ElementEvictionData elementEvictionData)
Sets this element's eviction data instance.
|
void |
setEternal(boolean eternal)
Sets whether the element is eternal.
|
(package private) void |
setId(long id)
Sets the element identifier (this field is used internally by ehcache).
|
protected void |
setLifespanDefaults(int tti,
int ttl,
boolean eternal)
Set the default parameters of this element - those from its enclosing cache.
|
void |
setTimeToIdle(int timeToIdleSeconds)
Sets time to idle
|
void |
setTimeToLive(int timeToLiveSeconds)
Sets time to Live
|
void |
setVersion(long version)
Sets the version attribute of the ElementAttributes object.
|
java.lang.String |
toString()
Returns a
String representation of the Element . |
void |
updateAccessStatistics()
Sets the last access time to now and increase the hit count.
|
void |
updateUpdateStatistics()
Sets the last access time to now without updating the hit count.
|
boolean |
usesCacheDefaultLifespan() |
private void |
writeObject(java.io.ObjectOutputStream out)
Custom serialization write logic
|
private static final long serialVersionUID
private static final org.slf4j.Logger LOG
private static final java.util.concurrent.atomic.AtomicLongFieldUpdater<Element> HIT_COUNT_UPDATER
private static final boolean ELEMENT_VERSION_AUTO
private static final long NOT_SET_ID
private final java.lang.Object key
private final java.lang.Object value
private volatile long version
private volatile long hitCount
private volatile int timeToLive
private volatile int timeToIdle
private transient volatile ElementEvictionData elementEvictionData
private volatile long lastUpdateTime
private volatile boolean cacheDefaultLifespan
private volatile long id
public Element(java.io.Serializable key, java.io.Serializable value, long version)
public Element(java.lang.Object key, java.lang.Object value, long version)
@Deprecated public Element(java.lang.Object key, java.lang.Object value, long version, long creationTime, long lastAccessTime, long nextToLastAccessTime, long lastUpdateTime, long hitCount)
nextToLastAccessTime
field is unused since
version 1.7, setting it will have no effect. Use
#Element(Object, Object, long, long, long, long, long)
insteadElement(Object, Object, long, long, long, long, long)
public Element(java.lang.Object key, java.lang.Object value, long version, long creationTime, long lastAccessTime, long lastUpdateTime, long hitCount)
public Element(java.lang.Object key, java.lang.Object value, long version, long creationTime, long lastAccessTime, long hitCount, boolean cacheDefaultLifespan, int timeToLive, int timeToIdle, long lastUpdateTime)
public Element(java.lang.Object key, java.lang.Object value, java.lang.Boolean eternal, java.lang.Integer timeToIdleSeconds, java.lang.Integer timeToLiveSeconds)
key
- any non null valuevalue
- any value, including nullseternal
- specify as non-null to override cache configurationtimeToIdleSeconds
- specify as non-null to override cache configurationtimeToLiveSeconds
- specify as non-null to override cache configurationpublic Element(java.io.Serializable key, java.io.Serializable value)
key
- value
- public Element(java.lang.Object key, java.lang.Object value)
key
- value
- @Deprecated public final java.io.Serializable getKey() throws CacheException
getObjectKey()
instead.CacheException
- if the key is not Serializable
.public final java.lang.Object getObjectKey()
getKey()
@Deprecated public final java.io.Serializable getValue() throws CacheException
getObjectValue()
instead.Serializable
. If not use getObjectValue()
.CacheException
- if the value is not Serializable
.public final java.lang.Object getObjectValue()
getValue()
public final boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public void setTimeToLive(int timeToLiveSeconds)
timeToLiveSeconds
- the number of seconds to livepublic void setTimeToIdle(int timeToIdleSeconds)
timeToIdleSeconds
- the number of seconds to idlepublic final int hashCode()
hashCode
in class java.lang.Object
public final void setVersion(long version)
version
- The new version valuevoid setId(long id)
id
- The new id valuelong getId()
boolean hasId()
@Deprecated public final void setCreateTime()
Note that in a Terracotta clustered environment, resetting the creation time will not have any effect.
public final long getCreationTime()
public final long getLatestOfCreationAndUpdateTime()
public final long getVersion()
public final long getLastAccessTime()
Element
will have a last access time equal to its create time.@Deprecated public final long getNextToLastAccessTime()
nextToLastAccessTime
field is unused since
version 1.7, retrieving it will return the lastAccessTime
. Use #getLastAccessTime() instead.getLastAccessTime()
public final long getHitCount()
public ElementEvictionData getElementEvictionData()
public void setElementEvictionData(ElementEvictionData elementEvictionData)
elementEvictionData
- this element's eviction datapublic final void resetAccessStatistics()
public final void updateAccessStatistics()
public final void updateUpdateStatistics()
public final java.lang.String toString()
String
representation of the Element
.toString
in class java.lang.Object
public final java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
Element
, with exactly the same field values as the one it was cloned from.java.lang.CloneNotSupportedException
private static java.lang.Object deepCopy(java.lang.Object oldValue) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public final long getSerializedSize()
public final boolean isSerializable()
public final boolean isKeySerializable()
public long getLastUpdateTime()
public boolean isExpired()
getExpirationTime()
is in the past.getExpirationTime()
public boolean isExpired(CacheConfiguration config)
getExpirationTime()
is in the past.
This method in addition propogates the default TTI/TTL values of the supplied cache into this element.
config
- config to take default parameters fromgetExpirationTime()
public long getExpirationTime()
public boolean isEternal()
public void setEternal(boolean eternal)
eternal
- public boolean isLifespanSet()
public int getTimeToLive()
public int getTimeToIdle()
public boolean usesCacheDefaultLifespan()
false
if this Element has a custom lifespanprotected void setLifespanDefaults(int tti, int ttl, boolean eternal)
tti
- TTI in secondsttl
- TTL in secondseternal
- true
if the element is eternal.private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException