在cache中存放数据的数据结构就是element类,主要就是存放key、value
下面是element类的介绍,其中@Deprecated的方法以及删除,一些简单的属性就不解释了
public class Element implements Serializable, Cloneable
{
private static final long serialVersionUID
= 1098572221246444544L
;
private static final Logger LOG
= LoggerFactory
.getLogger(Element
.class.getName());
private static final AtomicLongFieldUpdater
<Element> HIT_COUNT_UPDATER
= AtomicLongFieldUpdater
.newUpdater(Element
.class, "hitCount");
private static final boolean ELEMENT_VERSION_AUTO
= Boolean
.getBoolean("net.sf.ehcache.element.version.auto");
private static final long NOT_SET_ID
= 0L
;
@IgnoreSizeOf
private final Object key
;
private final Object value
;
private volatile long version
;
private volatile long hitCount
;
private volatile int timeToLive
;
private volatile int timeToIdle
;
private transient long creationTime
;
private transient long lastAccessTime
;
private volatile long lastUpdateTime
;
private volatile boolean cacheDefaultLifespan
;
private volatile long id
;
public final boolean equals(Object object
) {
if (object
!= null
&& object
instanceof Element) {
Element element
= (Element
)object
;
return this.key
!= null
&& element
.getObjectKey() != null
? this.key
.equals(element
.getObjectKey()) : false;
} else {
return false;
}
}
public boolean isExpired() {
if (this.isLifespanSet() && !this.isEternal()) {
long now
= this.getCurrentTime();
long expirationTime
= this.getExpirationTime();
return now
> expirationTime
;
} else {
return false;
}
}
public boolean isLifespanSet() {
return this.timeToIdle
!= -2147483648 || this.timeToLive
!= -2147483648;
}
public boolean isExpired(CacheConfiguration config
) {
if (this.cacheDefaultLifespan
) {
if (config
.isEternal()) {
this.timeToIdle
= 0;
this.timeToLive
= 0;
} else {
this.timeToIdle
= TimeUtil
.convertTimeToInt(config
.getTimeToIdleSeconds());
this.timeToLive
= TimeUtil
.convertTimeToInt(config
.getTimeToLiveSeconds());
}
}
return this.isExpired();
}
public long getExpirationTime() {
if (this.isLifespanSet() && !this.isEternal()) {
long expirationTime
= 0L
;
long ttlExpiry
= this.creationTime
+ TimeUtil
.toMillis(this.getTimeToLive());
long mostRecentTime
= Math
.max(this.creationTime
, this.lastAccessTime
);
long ttiExpiry
= mostRecentTime
+ TimeUtil
.toMillis(this.getTimeToIdle());
if (this.getTimeToLive() == 0 || this.getTimeToIdle() != 0 && this.lastAccessTime
!= 0L
) {
if (this.getTimeToLive() == 0) {
expirationTime
= ttiExpiry
;
} else {
expirationTime
= Math
.min(ttlExpiry
, ttiExpiry
);
}
} else {
expirationTime
= ttlExpiry
;
}
return expirationTime
;
} else {
return 9223372036854775807L
;
}
}
}
转载请注明原文地址: https://lol.8miu.com/read-11081.html