Commit 215ebc70 authored by HuangSheng's avatar HuangSheng Committed by nobodyiam

增加localCacheDir本地缓存配置路径可配置项

parent 87c65bfe
...@@ -65,7 +65,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -65,7 +65,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
private File findLocalCacheDir() { private File findLocalCacheDir() {
try { try {
String defaultCacheDir = m_configUtil.getDefaultLocalCacheDir(); String defaultCacheDir = m_configUtil.getLocalCacheDir();
Path path = Paths.get(defaultCacheDir); Path path = Paths.get(defaultCacheDir);
if (!Files.exists(path)) { if (!Files.exists(path)) {
Files.createDirectories(path); Files.createDirectories(path);
......
package com.ctrip.framework.apollo.util; package com.ctrip.framework.apollo.util;
import java.io.File;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -34,6 +35,7 @@ public class ConfigUtil { ...@@ -34,6 +35,7 @@ public class ConfigUtil {
private TimeUnit configCacheExpireTimeUnit = TimeUnit.MINUTES;//1 minute private TimeUnit configCacheExpireTimeUnit = TimeUnit.MINUTES;//1 minute
private long longPollingInitialDelayInMills = 2000;//2 seconds private long longPollingInitialDelayInMills = 2000;//2 seconds
private boolean autoUpdateInjectedSpringProperties = true; private boolean autoUpdateInjectedSpringProperties = true;
private String localCacheDir = this.getDefaultLocalCacheDir();
public ConfigUtil() { public ConfigUtil() {
initRefreshInterval(); initRefreshInterval();
...@@ -44,6 +46,7 @@ public class ConfigUtil { ...@@ -44,6 +46,7 @@ public class ConfigUtil {
initMaxConfigCacheSize(); initMaxConfigCacheSize();
initLongPollingInitialDelayInMills(); initLongPollingInitialDelayInMills();
initAutoUpdateInjectedSpringProperties(); initAutoUpdateInjectedSpringProperties();
initLocalCacheDir();
} }
/** /**
...@@ -205,11 +208,27 @@ public class ConfigUtil { ...@@ -205,11 +208,27 @@ public class ConfigUtil {
return onErrorRetryIntervalTimeUnit; return onErrorRetryIntervalTimeUnit;
} }
public String getDefaultLocalCacheDir() { private String getDefaultLocalCacheDir() {
String cacheRoot = isOSWindows() ? "C:\\opt\\data\\%s" : "/opt/data/%s"; String cacheRoot = isOSWindows() ? "C:\\opt\\data\\%s" : "/opt/data/%s";
return String.format(cacheRoot, getAppId()); return String.format(cacheRoot, getAppId());
} }
private void initLocalCacheDir() {
// 1. Get from System Property
String cacheRoot = System.getProperty("apollo.localCacheDir");
if (Strings.isNullOrEmpty(cacheRoot)) {
// 2. Get from app.properties
cacheRoot = Foundation.app().getProperty("apollo.localCacheDir", null);
}
if (!Strings.isNullOrEmpty(cacheRoot)) {
this.localCacheDir = String.format(cacheRoot + File.separator + "%s", getAppId());
}
}
public String getLocalCacheDir() {
return this.localCacheDir;
}
public boolean isInLocalMode() { public boolean isInLocalMode() {
try { try {
Env env = getApolloEnv(); Env env = getApolloEnv();
......
...@@ -178,7 +178,7 @@ public abstract class BaseIntegrationTest{ ...@@ -178,7 +178,7 @@ public abstract class BaseIntegrationTest{
} }
@Override @Override
public String getDefaultLocalCacheDir() { public String getLocalCacheDir() {
return ClassLoaderUtil.getClassPath(); return ClassLoaderUtil.getClassPath();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment