Skip to content

Commit

Permalink
Removed basePath handling in CacheableProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanLoebel committed Dec 26, 2019
1 parent 2f56a55 commit dd25354
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.JanLoebel</groupId>
<artifactId>json-schema-validation-starter</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,18 @@
public class CacheableJsonSchemaProvider extends DefaultJsonSchemaProvider {

private final Map<String, JsonSchema> cache = new ConcurrentHashMap<>();
private final String basePath;

public CacheableJsonSchemaProvider(String basePath) {
this.basePath = basePath;
}

public CacheableJsonSchemaProvider() {
this("");
}

@Override
public JsonSchema loadSchema(String url) {
final String fullPath = basePath + url;
if (cache.containsKey(fullPath)) {
return cache.get(fullPath);
if (cache.containsKey(url)) {
return cache.get(url);
}

return putToCache(fullPath, super.loadSchema(fullPath));
return putToCache(url, super.loadSchema(url));
}

private JsonSchema putToCache(String fullPath, JsonSchema jsonSchema) {
cache.put(fullPath, jsonSchema);
private JsonSchema putToCache(String url, JsonSchema jsonSchema) {
cache.put(url, jsonSchema);
return jsonSchema;
}

Expand Down

0 comments on commit dd25354

Please sign in to comment.