lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aviran" <amo...@infosciences.com>
Subject [PATCH] [Bug 30240] - FieldCacheImpl cache gets rebuilt every time
Date Wed, 21 Jul 2004 18:32:26 GMT
Index: FieldCacheImpl.java
===================================================================
RCS file:
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/FieldCacheI
mpl.java,v
retrieving revision 1.2
diff -u -r1.2 FieldCacheImpl.java
--- FieldCacheImpl.java	24 May 2004 22:51:42 -0000	1.2
+++ FieldCacheImpl.java	21 Jul 2004 18:25:02 -0000
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.util.Map;
 import java.util.WeakHashMap;
+import java.util.HashMap;
 
 /**
  * Expert: The default cache implementation, storing all values in memory.
@@ -40,7 +41,6 @@
 
   /** Expert: Every key in the internal cache is of this type. */
   static class Entry {
-    final IndexReader reader;  // which Reader
     final String field;        // which Field
     final int type;            // which SortField type
     final Object custom;       // which custom comparator
@@ -48,7 +48,6 @@
 
     /** Creates one of these objects. */
     Entry (IndexReader reader, String field, int type) {
-      this.reader = reader;
       this.field = field.intern();
       this.type = type;
       this.custom = null;
@@ -57,7 +56,6 @@
 
     /** Creates one of these objects for a custom comparator. */
     Entry (IndexReader reader, String field, Object custom) {
-      this.reader = reader;
       this.field = field.intern();
       this.type = SortField.CUSTOM;
       this.custom = custom;
@@ -68,7 +66,7 @@
     public boolean equals (Object o) {
       if (o instanceof Entry) {
         Entry other = (Entry) o;
-        if (other.reader == reader && other.field == field && other.type
==
type) {
+        if (other.field == field && other.type == type) {
           if (other.custom == null) {
             if (custom == null) return true;
           } else if (other.custom.equals (custom)) {
@@ -93,7 +91,9 @@
   Object lookup (IndexReader reader, String field, int type) {
     Entry entry = new Entry (reader, field, type);
     synchronized (this) {
-      return cache.get (entry);
+      HashMap readerCache = (HashMap)cache.get(reader);
+      if (readerCache == null) return null;
+      return readerCache.get (entry);
     }
   }
 
@@ -101,7 +101,9 @@
   Object lookup (IndexReader reader, String field, Object comparer) {
     Entry entry = new Entry (reader, field, comparer);
     synchronized (this) {
-      return cache.get (entry);
+      HashMap readerCache = (HashMap)cache.get(reader);
+      if (readerCache == null) return null;
+      return readerCache.get (entry);
     }
   }
 
@@ -109,7 +111,12 @@
   Object store (IndexReader reader, String field, int type, Object value) {
     Entry entry = new Entry (reader, field, type);
     synchronized (this) {
-      return cache.put (entry, value);
+      HashMap readerCache = (HashMap)cache.get(reader);
+      if (readerCache == null) {
+        readerCache = new HashMap();
+        cache.put(reader,readerCache);
+      }
+      return readerCache.put (entry, value);
     }
   }
 
@@ -117,7 +124,12 @@
   Object store (IndexReader reader, String field, Object comparer, Object
value) {
     Entry entry = new Entry (reader, field, comparer);
     synchronized (this) {
-      return cache.put (entry, value);
+      HashMap readerCache = (HashMap)cache.get(reader);
+      if (readerCache == null) {
+        readerCache = new HashMap();
+        cache.put(reader, readerCache);
+      }
+      return readerCache.put (entry, value);
     }
   }
 

http://issues.apache.org/bugzilla/show_bug.cgi?id=30240

Mime
View raw message