public class Element extends Object implements Serializable, 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.Constructor and Description |
---|
Element(Object key,
Object value)
Constructor.
|
Element(Object key,
Object value,
boolean eternal)
Constructor
|
Element(Object key,
Object value,
Boolean eternal,
Integer timeToIdleSeconds,
Integer timeToLiveSeconds)
Deprecated.
|
Element(Object key,
Object value,
int timeToIdleSeconds,
int timeToLiveSeconds)
Constructor
|
Element(Object key,
Object value,
long version)
A full constructor.
|
Element(Object key,
Object value,
long version,
long creationTime,
long lastAccessTime,
long hitCount,
boolean cacheDefaultLifespan,
int timeToLive,
int timeToIdle,
long lastUpdateTime)
Constructor used by ElementData.
|
Element(Object key,
Object value,
long version,
long creationTime,
long lastAccessTime,
long lastUpdateTime,
long hitCount)
Constructor.
|
Element(Object key,
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(Serializable key,
Serializable value)
Constructor.
|
Element(Serializable key,
Serializable value,
long version)
A full constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Clones an Element.
|
boolean |
equals(Object object)
Equals comparison with another element, based on the key.
|
long |
getCreationTime()
Gets the creationTime of the Element
|
long |
getExpirationTime()
Returns the expiration time based on time to live.
|
long |
getHitCount()
Gets the hit count on this element.
|
Serializable |
getKey()
Deprecated.
Please use
getObjectKey() instead. |
long |
getLastAccessTime()
Gets the last access time of this element.
|
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. |
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.
|
int |
getTimeToIdle() |
int |
getTimeToLive() |
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.
|
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.
|
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 |
setEternal(boolean eternal)
Sets whether the element is eternal.
|
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
Value must be a positive integer, 0 means infinite time to idle.
|
void |
setTimeToLive(int timeToLiveSeconds)
Sets time to Live
Value must be a positive integer, 0 means infinite time to live.
|
void |
setVersion(long version)
Sets the version attribute of the ElementAttributes object.
|
String |
toString()
|
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() |
public Element(Serializable key, Serializable value, long version)
public Element(Object key, Object value, long version)
@Deprecated public Element(Object key, 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(Object key, Object value, long version, long creationTime, long lastAccessTime, long lastUpdateTime, long hitCount)
public Element(Object key, Object value, long version, long creationTime, long lastAccessTime, long hitCount, boolean cacheDefaultLifespan, int timeToLive, int timeToIdle, long lastUpdateTime)
public Element(Object key, Object value, int timeToIdleSeconds, int timeToLiveSeconds)
key
- any non null valuevalue
- any value, including nullstimeToIdleSeconds
- seconds to idletimeToLiveSeconds
- seconds to livepublic Element(Object key, Object value, boolean eternal)
key
- any non null valuevalue
- any value, including nullseternal
- whether this element is eternal@Deprecated public Element(Object key, Object value, Boolean eternal, Integer timeToIdleSeconds, 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(Serializable key, Serializable value)
key
- value
- @Deprecated public final Serializable getKey() throws CacheException
getObjectKey()
instead.CacheException
- if the key is not Serializable
.public final Object getObjectKey()
getKey()
@Deprecated public final Serializable getValue() throws CacheException
getObjectValue()
instead.Serializable
. If not use getObjectValue()
.CacheException
- if the value is not Serializable
.public final Object getObjectValue()
getValue()
public final boolean equals(Object object)
public void setTimeToLive(int timeToLiveSeconds)
setEternal(boolean)
or make sure you also explicitly call setTimeToIdle(int)
.timeToLiveSeconds
- the number of seconds to livepublic void setTimeToIdle(int timeToIdleSeconds)
setEternal(boolean)
or make sure you also explicitly call setTimeToLive(int)
.timeToIdleSeconds
- the number of seconds to idlepublic final int hashCode()
public final void setVersion(long version)
version
- The new version value@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
has a lastAccessTime of 0, unless passed into the constructor.@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 final void resetAccessStatistics()
public final void updateAccessStatistics()
public final void updateUpdateStatistics()
public final Object clone() throws CloneNotSupportedException
clone
in class Object
Element
, with exactly the same field values as the one it was cloned from.CloneNotSupportedException
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.Copyright © 2003–2016 Terracotta, Inc.. All rights reserved.