Skip to content

Commit

Permalink
ValidationProcessor: don't cache {Array,Object}SchemaSelector results…
Browse files Browse the repository at this point in the history
… anymore

Given the issue, the plan is to create a ValidationProcessor for each
validation. As such, caching these doesn't make sense anymore.

Signed-off-by: Francis Galiegue <[email protected]>
  • Loading branch information
fge committed May 25, 2014
1 parent 5d8a29d commit 6faa665
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import com.github.fge.jsonschema.processors.data.SchemaContext;
import com.github.fge.jsonschema.processors.data.ValidatorList;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Lists;

import java.util.Collections;
Expand All @@ -54,8 +52,6 @@ public final class ValidationProcessor
private final MessageBundle syntaxMessages;
private final MessageBundle validationMessages;
private final Processor<SchemaContext, ValidatorList> processor;
private final LoadingCache<JsonNode, ArraySchemaSelector> arrayCache;
private final LoadingCache<JsonNode, ObjectSchemaSelector> objectCache;

public ValidationProcessor(final ValidationConfiguration cfg,
final Processor<SchemaContext, ValidatorList> processor)
Expand All @@ -65,8 +61,6 @@ public ValidationProcessor(final ValidationConfiguration cfg,
this.processor = new CachingProcessor<SchemaContext, ValidatorList>(
processor, SchemaContextEquivalence.getInstance()
);
arrayCache = CacheBuilder.newBuilder().build(arrayLoader());
objectCache = CacheBuilder.newBuilder().build(objectLoader());
}

@Override
Expand Down Expand Up @@ -155,7 +149,7 @@ private void processArray(final ProcessingReport report,
final JsonNode node = instance.getNode();

final JsonNode digest = ArraySchemaDigester.getInstance().digest(schema);
final ArraySchemaSelector selector = arrayCache.getUnchecked(digest);
final ArraySchemaSelector selector = new ArraySchemaSelector(digest);

final int size = node.size();

Expand Down Expand Up @@ -184,7 +178,7 @@ private void processObject(final ProcessingReport report,

final JsonNode digest = ObjectSchemaDigester.getInstance()
.digest(schema);
final ObjectSchemaSelector selector = objectCache.getUnchecked(digest);
final ObjectSchemaSelector selector = new ObjectSchemaSelector(digest);

final List<String> fields = Lists.newArrayList(node.fieldNames());
Collections.sort(fields);
Expand Down

0 comments on commit 6faa665

Please sign in to comment.