Skip to content

Commit 36644bc

Browse files
author
mmolina
committed
Backward compatibility for enableCache flag
1 parent 6661468 commit 36644bc

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/main/java/com/github/fge/jsonschema/core/load/configuration/LoadingConfiguration.java

+13
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ public JsonNodeReader getReader()
233233
return reader;
234234
}
235235

236+
/**
237+
* Return if we want to cache loaded schema or not
238+
* note that this do not affect preloadedSchema that are always cached
239+
*
240+
* @deprecated Use cacheSize getter instead to get the cache size
241+
*
242+
* @return if the cache has to be enabled
243+
*/
244+
@Deprecated
245+
public boolean getEnableCache() {
246+
return this.cacheSize != 0;
247+
}
248+
236249
/**
237250
* Return the size of the cache to use
238251
* note that this do not affect preloadedSchema that are always cached

src/main/java/com/github/fge/jsonschema/core/load/configuration/LoadingConfigurationBuilder.java

+24-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public final class LoadingConfigurationBuilder
5757
* EnumSets to collect them, so we have to do that...
5858
*/
5959
private static final EnumSet<JsonParser.Feature> DEFAULT_PARSER_FEATURES;
60+
61+
private static final int DEFAULT_CACHE_SIZE = 512;
6062

6163
static {
6264
DEFAULT_PARSER_FEATURES = EnumSet.noneOf(JsonParser.Feature.class);
@@ -78,9 +80,9 @@ public final class LoadingConfigurationBuilder
7880
URITranslatorConfiguration translatorCfg;
7981

8082
/**
81-
* Cache size is 4096 by default
83+
* Cache size is 512 by default
8284
*/
83-
int cacheSize = 4096;
85+
int cacheSize = DEFAULT_CACHE_SIZE;
8486

8587
/**
8688
* Dereferencing mode
@@ -134,11 +136,29 @@ public final class LoadingConfigurationBuilder
134136
parserFeatures = EnumSet.copyOf(cfg.parserFeatures);
135137
cacheSize = cfg.cacheSize;
136138
}
139+
140+
/**
141+
* Should we enable caching of downloaded schemas
142+
*
143+
* @deprecated Just for backward compatibility
144+
* Use cacheSize setter instead to set the maximum size of the cache
145+
*
146+
* <p>Note that this does <b>not</b> affect preloaded schemas</p>
147+
*
148+
* @param enableCache if loaded schemas have to be cached
149+
* @return this
150+
*/
151+
@Deprecated
152+
public LoadingConfigurationBuilder setEnableCache(final boolean enableCache)
153+
{
154+
this.cacheSize = enableCache ? DEFAULT_CACHE_SIZE : 0;
155+
return this;
156+
}
137157

138158
/**
139159
* How many schemas should be cached
140-
* <p>Note setting to zero effectively disable the cache</p>
141-
* <p>Note not settting the chache size or setting to -1, creates an unlimited cache</p>
160+
* <p>Note setting to zero effectively disables the cache</p>
161+
* <p>Note settting to -1 creates an unlimited cache</p>
142162
* <p>Note that this does <b>not</b> affect preloaded schemas</p>
143163
*
144164
* @param cacheSize if loaded schemas have to be cached

src/main/java/com/github/fge/jsonschema/core/processing/CachingProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class CachingProcessor<IN extends MessageProvider, OUT extends Mess
5353
private static final MessageBundle BUNDLE
5454
= MessageBundles.getBundle(JsonSchemaCoreMessageBundle.class);
5555

56-
public static final int DEFAULT_CACHE_SIZE = 4096;
56+
private static final int DEFAULT_CACHE_SIZE = 512;
5757

5858
/**
5959
* The wrapped processor

0 commit comments

Comments
 (0)