标签:hashcode ehcache 缓存机制 cache
public final Element get(Object key) throws IllegalStateException, CacheException {
checkStatus();
if (disabled) {
return null;
}
if (isStatisticsEnabled()) {
long start = System.currentTimeMillis();
Element element = searchInStoreWithStats(key);
//todo is this expensive. Maybe ditch.
long end = System.currentTimeMillis();
liveCacheStatisticsData.addGetTimeMillis(end - start);
return element;
} else {
return searchInStoreWithoutStats(key, false, true);
}
}其中Elememt是键值对对象,Element的构造方法有好多重构,有个关键的方法: public Element(final Serializable key, final Serializable value, final long version) {
this((Object) key, (Object) value, version);
} public boolean containsKey(Object key) {
int hash = hash(key.hashCode());
return segmentFor(hash).containsKey(key, hash);
}最终ehcache会调用hashCode()方法,对象的比较变成了hash的比较。标签:hashcode ehcache 缓存机制 cache
原文地址:http://blog.csdn.net/gklifg/article/details/38067777