理解Lucene/Solr的缓存

map=newLinkedHashMap<K,V>(initialSize,0.75f,true){@OverrideprotectedbooleanremoveEldestEntry(Map.Entryeldest){if(size()>limit){//incrementevictionsregardlessofstate.//thisdoesn’tneedtobesynchronizedbecauseitwill//onlybecalledinthecontextofahigherlevelsynchronizedblock.evictions++;stats.evictions.incrementAndGet();returntrue;}returnfalse;}};

//sincethewantToKeepgroupislikelytobebiggerthanwantToRemove,checkitfirstif(thisEntry>newestEntry-wantToKeep){//thisentryisguaranteednottobeinthebottom//group,sodonothing.numKept++;newOldestEntry=Math.min(thisEntry,newOldestEntry);}elseif(thisEntry<oldestEntry+wantToRemove){//entryinbottomgroup?//thisentryisguaranteedtobeinthebottomgroup//soimmediatelyremoveitfromthemap.evictEntry(ce.key);numRemoved++;}else{//Thisentry*could*beinthebottomgroup.//Collecttheseentriestoavoidanotherfullpass…thisiswasted//effortifenoughentriesarenormallyremovedinthisfirstpass.//Analternateimplcouldmakeafullsecondpass.if(eSize<eset.length-1){eset[eSize++]=ce;newNewestEntry=Math.max(thisEntry,newNewestEntry);newOldestEntry=Math.min(thisEntry,newOldestEntry);}}}

privatestaticclassCacheEntry<K,V>implementsComparable<CacheEntry<K,V>>{Kkey;Vvalue;volatileAtomicLonghits=newAtomicLong(0);longhitsCopy=0;volatilelonglastAccessed=0;longlastAccessedCopy=0;publicCacheEntry(Kkey,Vvalue,longlastAccessed){this.key=key;this.value=value;this.lastAccessed=lastAccessed;}

markAndSweep方法的核心代码如下:

那些无法讲述的悲伤和苍凉,

理解Lucene/Solr的缓存

相关文章:

你感兴趣的文章:

标签云: