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 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 volatile boolean | |
| private transient long | creationTime
The creation time. |
| private static final boolean | |
| private static final AtomicLongFieldUpdater | |
| private volatile long | hitCount
The number of times the element was hit. |
| private volatile long | |
| private final Object | key
the cache key. |
| private transient long | lastAccessTime
The last access time. |
| private volatile 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 final Logger | |
| private static final long | |
| private static final long | serialVersionUID
serial version Updated for version 1.2, 1.2.1 and 1.7 |
| private volatile int | timeToIdle
The amount of time for the element to idle, in seconds. |
| private volatile int | timeToLive
The amount of time for the element to live, in seconds. |
| private final Object | value
the value. |
| private volatile long | version
version of the element. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | Element(final Object key, final Object value, final long version, final long creationTime, final long lastAccessTime, final long nextToLastAccessTime, final long lastUpdateTime, final long hitCount)
Deprecated
The
Constructor.
nextToLastAccessTime field is unused since
version 1.7, setting it will have no effect. Use
#Element(Object, Object, long, long, long, long, long)
instead
|
| public | |
| public | |
| public | |
| public | |
| public | Element(final Object
any non null value key, final Object any value, including nulls value, final Boolean specify as non-null to override cache configuration eternal, final Integer specify as non-null to override cache configuration timeToIdleSeconds, final Integer specify as non-null to override cache configuration timeToLiveSeconds)
Deprecated
Constructor used by ehcache-server
timeToIdleSeconds and timeToLiveSeconds will have precedence over eternal.
|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final Object | Returns: a newElement, with exactly the same field values as the one it was cloned from.Overrides java. |
| private static Object | |
| public final boolean | equals(final Object
the reference object with which to compare. object)Overrides java. |
| public final long | |
| pack-priv long | |
| public long | Returns: the time to expirationReturns the expiration time based on time to live. |
| public final long | |
| pack-priv long | |
| public final Serializable | Returns: The key value.
Deprecated
Please use
Gets the key attribute of the Element object.
getObjectKey() instead.
|
| public final long | Returns: last access time in unix epochGets the last access time of this element. |
| public long | Returns: the time when the last update occured. If this is the original Element, the time will be nullIf 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. |
| public final long | Returns: if never updated, creation time is returned, otherwise updated timeCalculates the latest of creation and update time |
| public final long | getNextToLastAccessTime()
Deprecated
The
Gets the next to last access time.
nextToLastAccessTime field is unused since
version 1.7, retrieving it will return the lastAccessTime. Use #getLastAccessTime() instead.
|
| public final Object | Returns: The key as an Object. i.e no restriction is placed on itGets the key attribute of the Element object. |
| public final Object | Returns: The value as an Object. i.e no restriction is placed on itGets the value attribute of the Element object as an Object. |
| public final long | |
| public int | |
| public int | |
| public final Serializable | getValue()
Deprecated
Please use
Gets the value attribute of the Element object.
getObjectValue() instead.
|
| public final long | |
| public final int | |
| pack-priv boolean | |
| public boolean | |
| public boolean | Returns: true if the Element is expired, otherwise false. If no lifespan has been set for the Element it is considered not able to expire.An element is expired if the expiration time as given by |
| public boolean | Returns: true if the Element is expired, otherwise false. If no lifespan has been set for the Element it is considered not able to expire.config to take default parameters from config)An element is expired if the expiration time as given by |
| public final boolean | Returns: true if the element's key is SerializableWhether the element's key may be Serialized. |
| public boolean | |
| public final boolean | |
| private void | |
| public final void | |
| public final void | setCreateTime()
Deprecated
Resetting the creation time is not recommended as of version
1.7
Sets the creationTime attribute of the ElementAttributes object.
|
| public void | |
| pack-priv void | setId(final long
The new id value id)Sets the element identifier (this field is used internally by ehcache). |
| protected void | setLifespanDefaults(int
TTI in seconds tti, int TTL in seconds ttl, boolean true if the element is eternal.Set the default parameters of this element - those from its enclosing cache. |
| public void | setTimeToIdle(final int
the number of seconds to idle timeToIdleSeconds)Sets time to idle Value must be a positive integer, 0 means infinite time to idle. |
| public void | setTimeToLive(final int
the number of seconds to live timeToLiveSeconds)Sets time to Live Value must be a positive integer, 0 means infinite time to live. |
| public final void | setVersion(final long
The new version value version)Sets the version attribute of the ElementAttributes object. |
| public final String | |
| public final void | |
| public final void | |
| public boolean | |
| private void |
| cacheDefaultLifespan | back to summary |
|---|---|
| private volatile boolean cacheDefaultLifespan | |
| creationTime | back to summary |
|---|---|
| private transient long creationTime The creation time. | |
| ELEMENT_VERSION_AUTO | back to summary |
|---|---|
| private static final boolean ELEMENT_VERSION_AUTO | |
| HIT_COUNT_UPDATER | back to summary |
|---|---|
| private static final AtomicLongFieldUpdater<Element> HIT_COUNT_UPDATER | |
| hitCount | back to summary |
|---|---|
| private volatile long hitCount The number of times the element was hit. | |
| id | back to summary |
|---|---|
| private volatile long id | |
| key | back to summary |
|---|---|
| private final Object key the cache key. | |
| lastAccessTime | back to summary |
|---|---|
| private transient long lastAccessTime The last access time. | |
| lastUpdateTime | back to summary |
|---|---|
| private volatile 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. The creation time will be the creation time of the new Element, not the original one, so that TTL concepts still work. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| NOT_SET_ID | back to summary |
|---|---|
| private static final long NOT_SET_ID | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID serial version Updated for version 1.2, 1.2.1 and 1.7 | |
| timeToIdle | back to summary |
|---|---|
| private volatile int timeToIdle The amount of time for the element to idle, in seconds. 0 indicates unlimited. | |
| timeToLive | back to summary |
|---|---|
| private volatile int timeToLive The amount of time for the element to live, in seconds. 0 indicates unlimited. | |
| value | back to summary |
|---|---|
| private final Object value the value. | |
| version | back to summary |
|---|---|
| private volatile long version version of the element. System.currentTimeMillis() is used to compute version for updated elements. That way, the actual version of the updated element does not need to be checked. | |
| Element | back to summary |
|---|---|
| public Element(final Serializable key, final Serializable value, final long version) A full constructor. Creation time is set to the current time. Last Access Time is not set.
| |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final 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.
| |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final long version, final long creationTime, final long lastAccessTime, final long nextToLastAccessTime, final long lastUpdateTime, final long hitCount)
Deprecated The Constructor.
| |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final long version, final long creationTime, final long lastAccessTime, final long lastUpdateTime, final long hitCount) Constructor.
| |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final long version, final long creationTime, final long lastAccessTime, final long hitCount, final boolean cacheDefaultLifespan, final int timeToLive, final int timeToIdle, final long lastUpdateTime) Constructor used by ElementData. Needs to be public since ElementData might be in another classloader
| |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final int timeToIdleSeconds, final int timeToLiveSeconds) Constructor | |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final boolean eternal) Constructor | |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value, final Boolean eternal, final Integer timeToIdleSeconds, final Integer timeToLiveSeconds)
Deprecated
Constructor used by ehcache-server timeToIdleSeconds and timeToLiveSeconds will have precedence over eternal. Which means that what ever eternal says, non-null timeToIdleSeconds or timeToLiveSeconds will result in the element not being eternal
| |
| Element | back to summary |
|---|---|
| public Element(final Serializable key, final Serializable value) Constructor. | |
| Element | back to summary |
|---|---|
| public Element(final Object key, final Object value) Constructor.
| |
| clone | back to summary |
|---|---|
| public final Object clone() throws CloneNotSupportedException Overrides java. 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.
| |
| deepCopy | back to summary |
|---|---|
| private static Object deepCopy(final Object oldValue) throws IOException, ClassNotFoundException | |
| equals | back to summary |
|---|---|
| public final boolean equals(final Object object) Overrides java. Equals comparison with another element, based on the key.
| |
| getCreationTime | back to summary |
|---|---|
| public final long getCreationTime() Gets the creationTime of the Element
| |
| getCurrentTime | back to summary |
|---|---|
| pack-priv long getCurrentTime() Seam for testing purposes
| |
| getExpirationTime | back to summary |
|---|---|
| public long getExpirationTime() Returns the expiration time based on time to live. If this element also has a time to idle setting, the expiry time will vary depending on whether the element is accessed.
| |
| getHitCount | back to summary |
|---|---|
| public final long getHitCount() Gets the hit count on this element. | |
| getId | back to summary |
|---|---|
| pack-priv long getId() Gets the element identifier (this field is used internally by ehcache)
| |
| getKey | back to summary |
|---|---|
| public final Serializable getKey() throws CacheException
Deprecated Please use Gets the key attribute of the Element object.
| |
| getLastAccessTime | back to summary |
|---|---|
| public final long getLastAccessTime() Gets the last access time of this element.
Access means the element was written into a cache or read from it.
When first instantiated an
| |
| getLastUpdateTime | back to summary |
|---|---|
| public 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. The creation time will be the creation time of the new Element, not the original one, so that TTL concepts still work.
| |
| getLatestOfCreationAndUpdateTime | back to summary |
|---|---|
| public final long getLatestOfCreationAndUpdateTime() Calculates the latest of creation and update time
| |
| getNextToLastAccessTime | back to summary |
|---|---|
| public final long getNextToLastAccessTime()
Deprecated The Gets the next to last access time.
| |
| getObjectKey | back to summary |
|---|---|
| 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. | |
| getObjectValue | back to summary |
|---|---|
| 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.
| |
| getSerializedSize | back to summary |
|---|---|
| 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. If the key or value of the Element is not Serializable, an error will be logged and 0 will be returned.
| |
| getTimeToIdle | back to summary |
|---|---|
public int getTimeToIdle()
| |
| getTimeToLive | back to summary |
|---|---|
public int getTimeToLive()
| |
| getValue | back to summary |
|---|---|
| public final Serializable getValue() throws CacheException
Deprecated Please use Gets the value attribute of the Element object.
| |
| getVersion | back to summary |
|---|---|
| public final long getVersion() Gets the version attribute of the ElementAttributes object.
| |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Overrides java. Gets the hashcode, based on the key.
| |
| hasId | back to summary |
|---|---|
| pack-priv boolean hasId() Determines if an Id has been set on this element
| |
| isEternal | back to summary |
|---|---|
public boolean isEternal()
| |
| isExpired | back to summary |
|---|---|
| public boolean isExpired() An element is expired if the expiration time as given by
| |
| isExpired | back to summary |
|---|---|
| public boolean isExpired(CacheConfiguration config) An element is expired if the expiration time as given by This method in addition propogates the default TTI/TTL values of the supplied cache into this element.
| |
| isKeySerializable | back to summary |
|---|---|
| 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.
| |
| isLifespanSet | back to summary |
|---|---|
| public boolean isLifespanSet() Whether any combination of eternal, TTL or TTI has been set.
| |
| isSerializable | back to summary |
|---|---|
| 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. This method was tweaked in 1.6 as it has been shown that Serializable classes can be serializaed as can null, regardless of what class it is a null of. ObjectOutputStream.write(null) works and ObjectInputStream.read() will read null back.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException Custom serialization read logic | |
| resetAccessStatistics | back to summary |
|---|---|
| public final void resetAccessStatistics() Resets the hit count to 0 and the last access time to now. Used when an Element is put into a cache. | |
| setCreateTime | back to summary |
|---|---|
| public final void setCreateTime()
Deprecated Resetting the creation time is not recommended as of version 1.7 Sets the creationTime attribute of the ElementAttributes object. Note that in a Terracotta clustered environment, resetting the creation time will not have any effect.
| |
| setEternal | back to summary |
|---|---|
| public void setEternal(final boolean eternal) Sets whether the element is eternal. | |
| setId | back to summary |
|---|---|
| pack-priv void setId(final long id) Sets the element identifier (this field is used internally by ehcache). Setting this field in application code will not be preserved
| |
| setLifespanDefaults | back to summary |
|---|---|
| protected void setLifespanDefaults(int tti, int ttl, boolean eternal) Set the default parameters of this element - those from its enclosing cache.
| |
| setTimeToIdle | back to summary |
|---|---|
| public void setTimeToIdle(final int timeToIdleSeconds) Sets time to idle Value must be a positive integer, 0 means infinite time to idle.
If calling this method with 0 as the parameter, consider using
| |
| setTimeToLive | back to summary |
|---|---|
| public void setTimeToLive(final int timeToLiveSeconds) Sets time to Live Value must be a positive integer, 0 means infinite time to live.
If calling this method with 0 as the parameter, consider using
| |
| setVersion | back to summary |
|---|---|
| public final void setVersion(final long version) Sets the version attribute of the ElementAttributes object.
| |
| toString | back to summary |
|---|---|
| public final String toString() Overrides java. Returns a
| |
| updateAccessStatistics | back to summary |
|---|---|
| public final void updateAccessStatistics() Sets the last access time to now and increase the hit count. | |
| updateUpdateStatistics | back to summary |
|---|---|
| public final void updateUpdateStatistics() Sets the last access time to now without updating the hit count. | |
| usesCacheDefaultLifespan | back to summary |
|---|---|
public boolean usesCacheDefaultLifespan()
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream out) throws IOException Custom serialization write logic | |