From: Wolfgang M. M. <wol...@us...> - 2004-08-12 18:54:59
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage/cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11331/src/org/exist/storage/cache Modified Files: LRUCache.java ClockCache.java Log Message: Switched back to simple LRU page replacement strategy for document data in dom.dbx. As every page is accessed at most two times during storage, the LRDCache did not work very well. Improved the LRU implementation. Index: ClockCache.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/cache/ClockCache.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ClockCache.java 12 Jul 2004 17:17:41 -0000 1.18 --- ClockCache.java 12 Aug 2004 18:54:19 -0000 1.19 *************** *** 88,91 **** --- 88,92 ---- if (bucket < 0) bucket = i; + } else old.setReferenceCount(0); Index: LRUCache.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/cache/LRUCache.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LRUCache.java 8 Jun 2004 08:16:07 -0000 1.4 --- LRUCache.java 12 Aug 2004 18:54:19 -0000 1.5 *************** *** 27,30 **** --- 27,31 ---- import org.exist.util.hashtable.Long2ObjectHashMap; + import org.exist.util.hashtable.SequencedLongHashMap; /** *************** *** 34,39 **** private int max; ! private LinkedList stack = new LinkedList(); ! private Long2ObjectHashMap map; private int hits = 0; --- 35,39 ---- private int max; ! private SequencedLongHashMap map; private int hits = 0; *************** *** 42,46 **** public LRUCache(int size) { this.max = size; ! this.map = new Long2ObjectHashMap(size); } --- 42,46 ---- public LRUCache(int size) { this.max = size; ! this.map = new SequencedLongHashMap(size); } *************** *** 56,64 **** */ public void add(Cacheable item) { ! if(stack.size() == max) { ! removeOne(); } map.put(item.getKey(), item); - stack.addLast(item); } --- 56,63 ---- */ public void add(Cacheable item) { ! if(map.size() == max) { ! removeOne(item); } map.put(item.getKey(), item); } *************** *** 86,90 **** */ public void remove(Cacheable item) { - stack.remove(item); map.remove(item.getKey()); } --- 85,88 ---- *************** *** 95,99 **** public void flush() { Cacheable next; ! for(Iterator i = stack.iterator(); i.hasNext(); ) { next = (Cacheable)i.next(); next.sync(); --- 93,97 ---- public void flush() { Cacheable next; ! for(Iterator i = map.valueIterator(); i.hasNext(); ) { next = (Cacheable)i.next(); next.sync(); *************** *** 107,111 **** public boolean hasDirtyItems() { Cacheable next; ! for(Iterator i = stack.iterator(); i.hasNext(); ) { next = (Cacheable)i.next(); if(next.isDirty()) --- 105,109 ---- public boolean hasDirtyItems() { Cacheable next; ! for(Iterator i = map.valueIterator(); i.hasNext(); ) { next = (Cacheable)i.next(); if(next.isDirty()) *************** *** 126,130 **** */ public int getUsedBuffers() { ! return stack.size(); } --- 124,128 ---- */ public int getUsedBuffers() { ! return map.size(); } *************** *** 149,158 **** } ! private final void removeOne() { ! Cacheable first = (Cacheable)stack.removeFirst(); ! if(!stack.contains(first)) { ! map.remove(first.getKey()); ! first.sync(); ! } } } --- 147,161 ---- } ! private final void removeOne(Cacheable item) { ! boolean removed = false; ! do { ! Cacheable cached = (Cacheable)map.removeFirst(); ! if(cached.allowUnload() && cached.getKey() != item.getKey()) { ! cached.sync(); ! removed = true; ! } else { ! map.put(cached.getKey(), cached); ! } ! } while(!removed); } } |