Lines 46-51
Link Here
|
46 |
import java.net.URL; |
46 |
import java.net.URL; |
47 |
import java.util.logging.Level; |
47 |
import java.util.logging.Level; |
48 |
import java.util.logging.Logger; |
48 |
import java.util.logging.Logger; |
|
|
49 |
import java.util.concurrent.ConcurrentHashMap; |
49 |
import org.netbeans.modules.parsing.impl.indexing.DeletedIndexable; |
50 |
import org.netbeans.modules.parsing.impl.indexing.DeletedIndexable; |
50 |
import org.netbeans.modules.parsing.impl.indexing.FileObjectIndexable; |
51 |
import org.netbeans.modules.parsing.impl.indexing.FileObjectIndexable; |
51 |
import org.netbeans.modules.parsing.impl.indexing.SPIAccessor; |
52 |
import org.netbeans.modules.parsing.impl.indexing.SPIAccessor; |
Lines 66-71
Link Here
|
66 |
private final org.netbeans.modules.parsing.lucene.support.IndexDocument spi; |
67 |
private final org.netbeans.modules.parsing.lucene.support.IndexDocument spi; |
67 |
private final URL root; |
68 |
private final URL root; |
68 |
|
69 |
|
|
|
70 |
private final static ConcurrentHashMap<String,URL> cachedUrls = new ConcurrentHashMap(10); |
69 |
private volatile URL cachedUrl; |
71 |
private volatile URL cachedUrl; |
70 |
private volatile FileObject cachedFile; |
72 |
private volatile FileObject cachedFile; |
71 |
|
73 |
|
Lines 87-93
Link Here
|
87 |
} |
89 |
} |
88 |
|
90 |
|
89 |
public URL getUrl() { |
91 |
public URL getUrl() { |
90 |
if (cachedUrl == null) { |
92 |
String cacheKey = root+spi.getPrimaryKey(); |
|
|
93 |
if (cachedUrls.containsKey(cacheKey)) |
94 |
cachedUrl = cachedUrls.get(cacheKey); |
95 |
else if (cachedUrl == null) { |
91 |
URL url = null; |
96 |
URL url = null; |
92 |
try { |
97 |
try { |
93 |
url = Util.resolveUrl(root, spi.getPrimaryKey(), false); |
98 |
url = Util.resolveUrl(root, spi.getPrimaryKey(), false); |
Lines 100-105
Link Here
|
100 |
cachedUrl = url; |
105 |
cachedUrl = url; |
101 |
} |
106 |
} |
102 |
} |
107 |
} |
|
|
108 |
|
109 |
/* Ensure the cached map retains maximal size of 10 */ |
110 |
synchronized (cachedUrls) { |
111 |
if (cachedUrls.size() >= 10) |
112 |
{ |
113 |
String oldestCachedFile = cachedUrls.keys().nextElement(); |
114 |
cachedUrls.remove(oldestCachedFile); |
115 |
} |
116 |
cachedUrls.putIfAbsent(cacheKey, cachedUrl); |
117 |
} |
103 |
} |
118 |
} |
104 |
return cachedUrl; |
119 |
return cachedUrl; |
105 |
} |
120 |
} |