Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config cache is not using SoftReference anymore. #1495

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions config/config/src/main/java/io/helidon/config/ConfigFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,6 @@

package io.helidon.config;

import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.time.Instant;
import java.util.AbstractMap;
import java.util.List;
Expand Down Expand Up @@ -49,7 +47,7 @@ final class ConfigFactory {
private final ConfigFilter filter;
private final ProviderImpl provider;
private final Function<String, List<String>> aliasGenerator;
private final ConcurrentMap<PrefixedKey, Reference<Config>> configCache;
private final ConcurrentMap<PrefixedKey, Config> configCache;
private final Flow.Publisher<ConfigDiff> changesPublisher;
private final Instant timestamp;

Expand Down Expand Up @@ -136,14 +134,8 @@ public Config config() {
*/
public Config config(ConfigKeyImpl prefix, ConfigKeyImpl key) {
PrefixedKey prefixedKey = new PrefixedKey(prefix, key);
Reference<Config> reference = configCache.compute(prefixedKey, (k, v) -> {
if (v == null || v.get() == null) {
return new SoftReference<>(createConfig(prefix, key));
} else {
return v;
}
});
return reference.get();

return configCache.computeIfAbsent(prefixedKey, it -> createConfig(prefix, key));
}

/**
Expand Down