X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java?ds=inline diff --git a/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java b/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java new file mode 100644 index 0000000..a476bd2 --- /dev/null +++ b/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java @@ -0,0 +1,121 @@ +package org.apache.lucene.util; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Map; + +/** + * Simple concurrent LRU cache, using a "double barrel" + * approach where two ConcurrentHashMaps record entries. + * + *
At any given time, one hash is primary and the other + * is secondary. {@link #get} first checks primary, and if + * that's a miss, checks secondary. If secondary has the + * entry, it's promoted to primary (NOTE: the key is + * cloned at this point). Once primary is full, the + * secondary is cleared and the two are swapped.
+ * + *This is not as space efficient as other possible + * concurrent approaches (see LUCENE-2075): to achieve + * perfect LRU(N) it requires 2*N storage. But, this + * approach is relatively simple and seems in practice to + * not grow unbounded in size when under hideously high + * load.
+ * + * @lucene.internal + */ + +final public class DoubleBarrelLRUCache