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

Add a switch to support to disable local file cache #243

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/Apollo.Configuration/ApolloOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public virtual string? MetaServer
/// <summary>ms. Default 300,000ms</summary>
public virtual int RefreshInterval { get; set; } = 5 * 60 * 1000; //5 minutes

public bool EnableLocalFileCache { get; set; } = true;

public string? LocalCacheDir { get; set; }

public IDictionary<string, string> Meta { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Expand Down
3 changes: 3 additions & 0 deletions src/Apollo.ConfigurationManager/Util/ConfigUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Com.Ctrip.Framework.Apollo.Enums;
using Com.Ctrip.Framework.Apollo.Foundation;
using Com.Ctrip.Framework.Apollo.Logging;

using System.Collections.ObjectModel;
using System.Configuration;

Expand Down Expand Up @@ -187,6 +188,8 @@ private void InitRefreshInterval()

public int RefreshInterval => _refreshInterval;

public bool EnableLocalFileCache => bool.TryParse(GetAppConfig(nameof(EnableLocalFileCache)), out var enableLocalFileCache) && enableLocalFileCache;

public string LocalCacheDir => GetAppConfig(nameof(LocalCacheDir)) ?? Path.Combine(ConfigConsts.DefaultLocalCacheDir, AppId);

public bool EnablePlaceholder => bool.TryParse(GetAppConfig(nameof(EnablePlaceholder)), out var enablePlaceholder) && enablePlaceholder;
Expand Down
3 changes: 3 additions & 0 deletions src/Apollo/IApolloOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Com.Ctrip.Framework.Apollo.Enums;

using System.Collections.ObjectModel;

namespace Com.Ctrip.Framework.Apollo;
Expand Down Expand Up @@ -44,6 +45,7 @@ public interface IApolloOptions : IDisposable
/// <summary>Refresh interval. ms</summary>
int RefreshInterval { get; }

bool EnableLocalFileCache { get; }
string? LocalCacheDir { get; }

HttpMessageHandler HttpMessageHandler { get; }
Expand All @@ -57,4 +59,5 @@ public interface IApolloOptions : IDisposable
#else
IReadOnlyCollection<string>? SpecialDelimiter { get; }
#endif

}
8 changes: 6 additions & 2 deletions src/Apollo/Internals/ConfigRepositoryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ private IConfigRepository CreateConfigRepository(string @namespace)
LogManager.CreateLogger(typeof(ConfigRepositoryFactory)).Warn($"==== Apollo is in local mode! Won't pull configs '{@namespace}' from remote server! ====");
return new LocalFileConfigRepository(@namespace, _options);
}

return new LocalFileConfigRepository(@namespace, _options, new RemoteConfigRepository(@namespace, _options, _httpUtil, _serviceLocator, _remoteConfigLongPollService));
var remoteRepo = new RemoteConfigRepository(@namespace, _options, _httpUtil, _serviceLocator, _remoteConfigLongPollService);
if (!_options.EnableLocalFileCache)
{
return remoteRepo;
}
return new LocalFileConfigRepository(@namespace, _options, remoteRepo);
}

public void Dispose()
Expand Down
Loading