From d0198d5ff5a56196c4582c6784d4b5378be65bee Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Mon, 18 Nov 2019 20:27:54 +0100 Subject: [PATCH] #1118 - Switch to ConcurrentReferenceHashMap to cache UriTemplate instances. We now use Spring's ConcurrentReferenceHashMap to keep instances of UriTemplate cached but at the same time allow the cache entries to be garbage collected if necessary. --- src/main/java/org/springframework/hateoas/UriTemplate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/UriTemplate.java b/src/main/java/org/springframework/hateoas/UriTemplate.java index ceb5d78f..c41f0cdb 100644 --- a/src/main/java/org/springframework/hateoas/UriTemplate.java +++ b/src/main/java/org/springframework/hateoas/UriTemplate.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -30,6 +29,7 @@ import java.util.stream.Collectors; import org.springframework.hateoas.TemplateVariable.VariableType; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.StringUtils; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; @@ -47,7 +47,7 @@ public class UriTemplate implements Iterable, Serializable { private static final Pattern VARIABLE_REGEX = Pattern.compile("\\{([\\?\\&#/]?)([\\w\\,*]+)\\}"); private static final long serialVersionUID = -1007874653930162262L; - private static final Map CACHE = new ConcurrentHashMap<>(); + private static final Map CACHE = new ConcurrentReferenceHashMap<>(); private final TemplateVariables variables; private String toString;