@@ -51,6 +51,7 @@ public static class Builder {
51
51
private final Map <String , String > uriMap = new HashMap <String , String >();
52
52
private boolean forceHttps = true ;
53
53
private boolean removeEmptyFragmentSuffix = true ;
54
+ private boolean enableUriSchemaCache = true ;
54
55
55
56
public Builder () {
56
57
// Adds support for creating {@link URL}s.
@@ -157,6 +158,11 @@ public Builder removeEmptyFragmentSuffix(boolean removeEmptyFragmentSuffix) {
157
158
return this ;
158
159
}
159
160
161
+ public Builder enableUriSchemaCache (boolean enableUriSchemaCache ) {
162
+ this .enableUriSchemaCache = enableUriSchemaCache ;
163
+ return this ;
164
+ }
165
+
160
166
public JsonSchemaFactory build () {
161
167
// create builtin keywords with (custom) formats.
162
168
return new JsonSchemaFactory (
@@ -169,7 +175,8 @@ public JsonSchemaFactory build() {
169
175
jsonMetaSchemas ,
170
176
uriMap ,
171
177
forceHttps ,
172
- removeEmptyFragmentSuffix
178
+ removeEmptyFragmentSuffix ,
179
+ enableUriSchemaCache
173
180
);
174
181
}
175
182
}
@@ -185,6 +192,7 @@ public JsonSchemaFactory build() {
185
192
private final ConcurrentMap <URI , JsonSchema > uriSchemaCache = new ConcurrentHashMap <URI , JsonSchema >();
186
193
private final boolean forceHttps ;
187
194
private final boolean removeEmptyFragmentSuffix ;
195
+ private final boolean enableUriSchemaCache ;
188
196
189
197
190
198
private JsonSchemaFactory (
@@ -197,7 +205,8 @@ private JsonSchemaFactory(
197
205
final Map <String , JsonMetaSchema > jsonMetaSchemas ,
198
206
final Map <String , String > uriMap ,
199
207
final boolean forceHttps ,
200
- final boolean removeEmptyFragmentSuffix ) {
208
+ final boolean removeEmptyFragmentSuffix ,
209
+ final boolean enableUriSchemaCache ) {
201
210
if (jsonMapper == null ) {
202
211
throw new IllegalArgumentException ("ObjectMapper must not be null" );
203
212
} else if (yamlMapper == null ) {
@@ -225,6 +234,7 @@ private JsonSchemaFactory(
225
234
this .uriMap = uriMap ;
226
235
this .forceHttps = forceHttps ;
227
236
this .removeEmptyFragmentSuffix = removeEmptyFragmentSuffix ;
237
+ this .enableUriSchemaCache = enableUriSchemaCache ;
228
238
}
229
239
230
240
/**
@@ -373,7 +383,7 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co
373
383
throw new JsonSchemaException (e );
374
384
}
375
385
376
- if (uriSchemaCache .containsKey (mappedUri )) {
386
+ if (enableUriSchemaCache && uriSchemaCache .containsKey (mappedUri )) {
377
387
JsonSchema cachedUriSchema = uriSchemaCache .get (mappedUri );
378
388
// This is important because if we use same JsonSchemaFactory for creating multiple JSONSchema instances,
379
389
// these schemas will be cached along with config. We have to replace the config for cached $ref references
@@ -404,7 +414,10 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co
404
414
validationContext .setConfig (config );
405
415
jsonSchema = new JsonSchema (validationContext , mappedUri , schemaNode );
406
416
}
407
- uriSchemaCache .put (mappedUri , jsonSchema );
417
+
418
+ if (enableUriSchemaCache ) {
419
+ uriSchemaCache .put (mappedUri , jsonSchema );
420
+ }
408
421
409
422
return jsonSchema ;
410
423
} finally {
0 commit comments