diff --git a/pom.xml b/pom.xml
index ce8e878..2106733 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
UTF-8
3.1
- 2.78
+ 2.81
5.2.5.Final
2.5.1
4.12
diff --git a/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigCache.java b/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigCache.java
new file mode 100644
index 0000000..acdfb83
--- /dev/null
+++ b/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigCache.java
@@ -0,0 +1,35 @@
+package org.endeavourhealth.common.config;
+
+import org.endeavourhealth.common.cache.ICache;
+import org.endeavourhealth.common.config.models.ConfigCacheEntry;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ConfigCache implements ICache {
+ private static Map _configCache = new HashMap<>();
+
+ @Override
+ public String getName() {
+ return "ConfigCache";
+ }
+
+ @Override
+ public long getSize() {
+ return _configCache.size();
+ }
+
+ @Override
+ public void clearCache() {
+ _configCache.clear();
+ }
+
+
+ public ConfigCacheEntry get(String configId, String appId) {
+ return _configCache.get(configId + appId);
+ }
+
+ public void put(String configId, String appId, ConfigCacheEntry cacheEntry) {
+ _configCache.put(configId + appId, cacheEntry);
+ }
+}
diff --git a/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigManager.java b/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigManager.java
index 1b5a1c6..5d1d903 100644
--- a/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigManager.java
+++ b/src/configmanager/src/main/java/org/endeavourhealth/common/config/ConfigManager.java
@@ -3,6 +3,7 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import com.fasterxml.jackson.databind.JsonNode;
+import org.endeavourhealth.common.cache.CacheManager;
import org.endeavourhealth.common.cache.ObjectMapperPool;
import org.endeavourhealth.common.config.db.DatabaseLayer;
import org.endeavourhealth.common.config.db.JdbcLayer;
@@ -12,8 +13,6 @@
import java.io.*;
import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Properties;
public class ConfigManager {
@@ -24,7 +23,7 @@ public class ConfigManager {
static DatabaseLayer _databaseLayer;
private static String _appId;
- private static Map _configCache = new HashMap<>();
+ private static ConfigCache _configCache;
static { //runs when the main class is loaded.
LOG.info("Config manager created");
@@ -32,6 +31,8 @@ public class ConfigManager {
LOG.info("Jboss logging switched to slf4j");
_databaseLayer = new JdbcLayer();
+ _configCache = new ConfigCache();
+ CacheManager.registerCache(_configCache);
}
public synchronized static void Initialize(String appId) throws ConfigManagerException {
@@ -80,11 +81,12 @@ public static String getConfiguration(String configId) {
public synchronized static String getConfiguration(String configId, String appIdParam) {
// Try to get from cache
- ConfigCacheEntry cacheEntry = _configCache.get(configId + appIdParam);
+ ConfigCacheEntry cacheEntry = _configCache.get(configId, appIdParam);
if (cacheEntry!=null && !cacheEntry.isExpired())
return cacheEntry.getConfigData();
- cacheEntry = _configCache.get(configId + APP_GLOBAL);
+ // If no app specific result, look for a global setting
+ cacheEntry = _configCache.get(configId, APP_GLOBAL);
if (cacheEntry!=null && !cacheEntry.isExpired())
return cacheEntry.getConfigData();
@@ -92,7 +94,7 @@ public synchronized static String getConfiguration(String configId, String appId
String data = _databaseLayer.getConfiguration(configId, appIdParam);
if (data != null) {
cacheEntry = new ConfigCacheEntry(data);
- _configCache.put(configId + appIdParam, cacheEntry);
+ _configCache.put(configId, appIdParam, cacheEntry);
return data;
}
@@ -100,7 +102,7 @@ public synchronized static String getConfiguration(String configId, String appId
data = _databaseLayer.getConfiguration(configId, APP_GLOBAL);
if (data != null) {
cacheEntry = new ConfigCacheEntry(data);
- _configCache.put(configId + APP_GLOBAL, cacheEntry);
+ _configCache.put(configId, APP_GLOBAL, cacheEntry);
return data;
}