Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions solr/core/src/java/org/apache/solr/schema/IndexSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.io.IOException;
import java.io.Writer;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -68,7 +70,6 @@
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.Cache;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Pair;
import org.apache.solr.common.util.SimpleOrderedMap;
Expand All @@ -80,7 +81,6 @@
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.similarities.SchemaSimilarityFactory;
import org.apache.solr.uninverting.UninvertingReader;
import org.apache.solr.util.ConcurrentLRUCache;
import org.apache.solr.util.PayloadUtils;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.slf4j.Logger;
Expand Down Expand Up @@ -145,8 +145,8 @@ public DynamicField[] getDynamicFields() {
private static final Set<String> FIELDTYPE_KEYS = Set.of("fieldtype", "fieldType");
private static final Set<String> FIELD_KEYS = Set.of("dynamicField", "field");

protected Cache<String, SchemaField> dynamicFieldCache =
new ConcurrentLRUCache<>(10000, 8000, 9000, 100, false, false, null);
protected final Cache<String, SchemaField> dynamicFieldCache =
Caffeine.newBuilder().initialCapacity(100).maximumSize(10000).build();

private Analyzer indexAnalyzer;
private Analyzer queryAnalyzer;
Expand Down Expand Up @@ -1390,7 +1390,7 @@ public boolean isDynamicField(String fieldName) {
public SchemaField getFieldOrNull(String fieldName) {
SchemaField f = fields.get(fieldName);
if (f != null) return f;
f = dynamicFieldCache.get(fieldName);
f = dynamicFieldCache.getIfPresent(fieldName);
if (f != null) return f;

for (DynamicField df : dynamicFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

package org.apache.solr.update.processor;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.Cache;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.util.ConcurrentLRUCache;

/**
* Adds new fields to documents based on a template pattern specified via Template.field request
Expand All @@ -41,7 +41,7 @@
*/
public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory {
private Cache<String, Resolved> templateCache =
new ConcurrentLRUCache<>(1000, 800, 900, 10, false, false, null);
Caffeine.newBuilder().initialCapacity(10).maximumSize(1000).build();
public static final String NAME = "template";

@Override
Expand Down Expand Up @@ -79,19 +79,18 @@ protected String getMyName() {

public static Resolved getResolved(
String template, Cache<String, Resolved> cache, Pattern pattern) {
Resolved r = cache == null ? null : cache.get(template);
if (r == null) {
r = new Resolved();
Matcher m = pattern.matcher(template);
while (m.find()) {
String variable = m.group(1);
r.startIndexes.add(m.start(0));
r.endOffsets.add(m.end(0));
r.variables.add(variable);
}
if (cache != null) cache.put(template, r);
}
return r;
return cache == null ? null : cache.get(
template, t -> {
var r = new Resolved();
Matcher m = pattern.matcher(t);
while (m.find()) {
String variable = m.group(1);
r.startIndexes.add(m.start(0));
r.endOffsets.add(m.end(0));
r.variables.add(variable);
}
return r;
});
}

/** Get a list of variables embedded in the template string. */
Expand Down
Loading