Skip to content

Commit

Permalink
SAK-44641 MBM containsKey producing wrong results upon expiration (sa…
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored Nov 9, 2020
1 parent 360fa61 commit b07140d
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,17 @@ public void destroy() {

@Override
public Map<String, String> getBundle(String baseName, String moduleName, Locale locale) {
Map<String, String> bundle = null;
String key = MessageBundleServiceImpl.getIndexKeyName(baseName, moduleName, locale != null ? locale.toString(): null);
log.debug("Retrieve bundle from cache with key = {}", key);

if (cache.containsKey(key)) {
log.debug("Cache contains the key = {}", key);
bundle = cache.get(key);
} else {
// bundle not in cache or expired
Map<String, String> bundle = cache.get(key);
if (bundle == null) {
// bundle not in cache or expired, never returns null
bundle = dbMessageBundleService.getBundle(baseName, moduleName, locale);
log.debug("Add bundle to cache with key = {}", key);
cache.put(key, bundle);
}

// ensure we always return a valid collection
if (bundle == null) {
log.debug("Null bundle found with key = {}", key);
bundle = Collections.emptyMap();
// cache the empty for negative lookups this prevents repeated db lookups for this key
cache.put(key, bundle);
}

return bundle;
}

Expand Down

0 comments on commit b07140d

Please sign in to comment.