Skip to content

Commit 909f1b3

Browse files
committed
Revert "message cache"
This reverts commit 7ed7d55.
1 parent 7ed7d55 commit 909f1b3

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

validator/src/main/java/io/avaje/validation/core/CoreAdapterBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
/** Builds and caches the ValidationAdapter adapters for DValidator. */
1616
final class CoreAdapterBuilder {
17-
public static final ValidationAdapter NOOP = (type, req, propertyName) -> true;
17+
1818
private final DValidator context;
1919
private final List<ValidationContext.AdapterFactory> factories = new ArrayList<>();
2020
private final List<ValidationContext.AnnotationFactory> annotationFactories = new ArrayList<>();
2121
private final Map<Object, ValidationAdapter<?>> adapterCache = new ConcurrentHashMap<>();
22+
private final MessageInterpolator interpolator;
2223

2324
CoreAdapterBuilder(
2425
DValidator context,
@@ -29,6 +30,7 @@ final class CoreAdapterBuilder {
2930
this.annotationFactories.addAll(userAnnotationFactories);
3031
this.annotationFactories.add(BasicAdapters.FACTORY);
3132
this.annotationFactories.add(NumberAdapters.FACTORY);
33+
interpolator = context.interpolator();
3234
}
3335

3436
/** Return the adapter from cache if exists else return null. */
@@ -74,6 +76,6 @@ <T> ValidationAdapter<T> buildAnnotation(Class<? extends Annotation> cls, Map<St
7476
}
7577
}
7678
// unknown annotations have noop
77-
return NOOP;
79+
return NoopAnnotationValidator.INSTANCE;
7880
}
7981
}

validator/src/main/java/io/avaje/validation/core/DValidator.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.lang.reflect.Type;
1010
import java.util.ArrayList;
1111
import java.util.Collections;
12-
import java.util.HashMap;
1312
import java.util.List;
1413
import java.util.Locale;
1514
import java.util.Map;
@@ -32,8 +31,6 @@ final class DValidator implements Validator, ValidationContext {
3231
private final MessageInterpolator interpolator;
3332
private final LocaleResolver localeResolver;
3433
private final DTemplateLookup templateLookup;
35-
private final Map<String, String> messageCache = new HashMap<>();
36-
3734

3835
DValidator(
3936
List<AdapterFactory> factories,
@@ -121,16 +118,12 @@ ValidationRequest request(@Nullable Locale locale) {
121118

122119
String interpolate(Message msg, Locale requestLocale) {
123120

124-
return messageCache.computeIfAbsent(
125-
requestLocale.toString() + msg.template(),
126-
k -> {
127-
// resolve the locale to use to produce the message
128-
final Locale locale = localeResolver.resolve(requestLocale);
129-
// lookup in resource bundles using resolved locale and template
130-
final String template = templateLookup.lookup(msg.template(), locale);
121+
// resolve the locale to use to produce the message
122+
final Locale locale = localeResolver.resolve(requestLocale);
123+
// lookup in resource bundles using resolved locale and template
124+
final String template = templateLookup.lookup(msg.template(), locale);
131125

132-
return interpolator.interpolate(template, msg.attributes());
133-
});
126+
return interpolator.interpolate(template, msg.attributes());
134127
}
135128

136129
/** Implementation of Validator.Builder. */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.avaje.validation.core;
2+
3+
import io.avaje.validation.adapter.ValidationAdapter;
4+
import io.avaje.validation.adapter.ValidationRequest;
5+
6+
final class NoopAnnotationValidator<T> implements ValidationAdapter<T> {
7+
public static final NoopAnnotationValidator INSTANCE = new NoopAnnotationValidator<>();
8+
9+
private NoopAnnotationValidator() {}
10+
11+
@Override
12+
public boolean validate(T type, ValidationRequest req, String propertyName) {
13+
// NOOP
14+
return true;
15+
}
16+
}

0 commit comments

Comments
 (0)