Skip to content

Commit bfbc5a9

Browse files
committed
Remove cache function
1 parent da36a39 commit bfbc5a9

17 files changed

+58
-182
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Appconfi
22

3-
[Appconfi](https://www.appconfi.com) - Service to centrally manage application settings and feature toggles for applications and services.
3+
[Appconfi] - Service to centrally manage application settings and feature toggles for applications and services.
44

55
## Installation
66

@@ -12,7 +12,7 @@ More info is available on [nuget](https://www.nuget.org/packages/Appconfi/)
1212

1313
## Usage
1414

15-
In order to use the Appconfi you will need to [create an account](https://appconfi.com/account/register).
15+
In order to use the Appconfi you will need to deploy an appconfi server and `/account/register`.
1616

1717
From there you can create your first application and setup your configuration. To use the Appconfi API to access your configuration go to `/accesskeys` there you can find the `application_id` and your `application_key`.
1818

@@ -41,6 +41,3 @@ var refreshInterval = TimeSpan.FromMinutes(1);
4141
var manager = Configuration.NewInstance(applicationId, apiKey, env, refreshInterval);
4242
```
4343

44-
## Links
45-
46-
* [Web](https://appconfi.com)

src/Appconfi.Example/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class Program
77
{
88
static void Main(string[] args)
99
{
10-
var applicationId = "530cfb60-da0a-491b-bad8-ff7122100bc1";
11-
var apiKey = "655759a7573e480f9d727ddf5ae31264";
12-
var env = "ES";
10+
var applicationId = "<here>";
11+
var apiKey = "<here>";
12+
var env = "[default]";
1313

1414
var manager = Configuration.NewInstance(
15-
new Uri("https://localhost:5001"),
15+
new Uri("<here>"),
1616
applicationId,
1717
apiKey,
1818
env,

src/Appconfi.Test/AppconfiManagerSpec.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,31 @@ public void AppconfiManager_IsFeatureEnabled_ValidKey_ReturnToggle()
118118
}
119119

120120
[TestMethod]
121-
public void AppconfiManager_IsFeatureEnabled_ValidKey_ReturnFromCache()
121+
public void AppconfiManager_IsFeatureEnabled_ValidKey_ReturnFromDefault()
122122
{
123123
var configurationStoreMock = new Mock<IConfigurationStore>();
124124
var configuration = new ApplicationConfiguration();
125125

126126
//Given a version
127127
configurationStoreMock.Setup(x => x.GetVersion()).Returns("1");
128-
//And given a cache
129-
Func<string, bool> cache = (key) => key == "feature.toggle";
130128

131-
var manager = new AppconfiManager(configurationStoreMock.Object, TimeSpan.FromSeconds(1), null, cache);
132-
var isEnabled = manager.IsFeatureEnabled("feature.toggle");
129+
var manager = new AppconfiManager(configurationStoreMock.Object, TimeSpan.FromSeconds(1));
130+
var isEnabled = manager.IsFeatureEnabled("feature.toggle", true);
133131

134132
Assert.IsTrue(isEnabled);
135133
}
136134

137135
[TestMethod]
138-
public void AppconfiManager_GetSetting_ValidKey_ReturnFromCache()
136+
public void AppconfiManager_GetSetting_ValidKey_ReturnFromDefault()
139137
{
140138
var configurationStoreMock = new Mock<IConfigurationStore>();
141139
var configuration = new ApplicationConfiguration();
142140

143141
//Given a version
144142
configurationStoreMock.Setup(x => x.GetVersion()).Returns("1");
145-
//And given a cache
146-
Func<string, string> cache = (key) => key == "cache-setting" ? "value" : "invalid";
147143

148-
var manager = new AppconfiManager(configurationStoreMock.Object, TimeSpan.FromSeconds(1), cache, null);
149-
var value = manager.GetSetting("cache-setting");
144+
var manager = new AppconfiManager(configurationStoreMock.Object, TimeSpan.FromSeconds(1));
145+
var value = manager.GetSetting("cache-setting", "value");
150146

151147
Assert.AreEqual("value", value);
152148
}

src/Appconfi.Web.Example/Controllers/WeatherForecastController.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class WeatherForecastController : ControllerBase
1616
};
1717

1818
private readonly ILogger<WeatherForecastController> _logger;
19-
private readonly IFeatureManager _featureManager;
19+
private readonly IAppconfiFeatureManager _featureManager;
2020

21-
public WeatherForecastController(ILogger<WeatherForecastController> logger, IFeatureManager featureManager)
21+
public WeatherForecastController(ILogger<WeatherForecastController> logger, IAppconfiFeatureManager featureManager)
2222
{
2323
_logger = logger;
2424
_featureManager = featureManager;
@@ -27,8 +27,10 @@ public WeatherForecastController(ILogger<WeatherForecastController> logger, IFea
2727
[HttpGet]
2828
public IEnumerable<WeatherForecast> Get()
2929
{
30-
if (!_featureManager.IsEnabled("feature.a"))
31-
return null;
30+
if (!_featureManager.IsEnabled("awesome_feature"))
31+
return Enumerable.Empty<WeatherForecast>() ;
32+
33+
3234

3335
var rng = new Random();
3436
return Enumerable.Range(1, 5).Select(index => new WeatherForecast

src/Appconfi.Web.Example/Startup.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ public void ConfigureServices(IServiceCollection services)
2727
{
2828
services.AddControllers();
2929
services.AddAppconfi(options => {
30-
options.Application = "530cfb60-da0a-491b-bad8-ff7122100bc1";
31-
options.Key = "655759a7573e480f9d727ddf5ae31264";
32-
options.Environment = "ES";
33-
options.BaseAddress = "https://localhost:5001";
30+
options.Application = "<here>";
31+
options.Key = "<here>";
32+
options.Environment = "<here>";
33+
options.BaseAddress = "<here>";
3434
options.CacheExpirationTime = TimeSpan.FromMinutes(1);
35-
options.UseFeatureToggleCache(typeof(Startup).Assembly, "features.json");
3635
});
3736
}
3837

src/Appconfi.Web/Appconfi.Web.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<PackageId>Appconfi.Web</PackageId>
6-
<Version>1.2.0</Version>
6+
<Version>1.3.0</Version>
77
<Authors>Appconfi's Team</Authors>
88
<Company>Appconfi</Company>
99
<Copyright>Copyright © Appconfi 2020</Copyright>
1010
<RepositoryUrl>https://github.com/appconfi/appconfi-csharp</RepositoryUrl>
1111
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
1212
<PackageReleaseNotes>
13+
Version 1.3.0
14+
* Remove cache function
15+
* Simplify logic
1316
Version 1.2.1
1417
* Adding web extensions
1518
</PackageReleaseNotes>

src/Appconfi.Web/AppconfiOptions.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
using System;
2-
using System.Reflection;
32

43
namespace Appconfi.Web
54
{
65
public class AppconfiOptions
76
{
8-
public AppconfiCacheConfiguration FeatureToggleCacheConfiguration { get; private set; }
97
public string BaseAddress { get; set; }
108
public string Application { get; set; }
119
public string Key { get; set; }
1210
public string Environment { get; set; } = "[default]";
1311
public TimeSpan CacheExpirationTime { get; set; } = TimeSpan.FromMinutes(5);
14-
15-
public AppconfiOptions UseFeatureToggleCache(Assembly assembly, string resourceFileName)
16-
{
17-
FeatureToggleCacheConfiguration = new AppconfiCacheConfiguration
18-
{
19-
Assembly = assembly,
20-
EmbeddedFilePath = resourceFileName
21-
};
22-
return this;
23-
}
2412
}
2513
}

src/Appconfi.Web/Extensions/DependencyInjection/AppconfiServiceCollectionExtensions.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using System;
3-
using Newtonsoft.Json;
4-
using System.Collections.Generic;
53

64
namespace Appconfi.Web.Extensions.DependencyInjection
75
{
86
public static class AppconfiServiceCollectionExtensions
97
{
10-
private static Func<string, bool> GetLocalFeatures(AppconfiCacheConfiguration config)
11-
{
12-
if (config == null)
13-
return null;
14-
15-
var embeddedResource = ResourceHelper.GetEmbeddedResource(config.EmbeddedFilePath, config.Assembly);
16-
IDictionary<string,string> cache = JsonConvert.DeserializeObject<Dictionary<string,string>>(embeddedResource);
17-
Func<string, bool> response = (feature) => {
18-
if (cache.ContainsKey(feature))
19-
return cache[feature] == "on";
20-
return false;
21-
};
22-
23-
return response;
24-
}
25-
268
public static IServiceCollection AddAppconfi(this IServiceCollection services, Action<AppconfiOptions> configure)
279
{
2810
var options = new AppconfiOptions();
@@ -33,13 +15,11 @@ public static IServiceCollection AddAppconfi(this IServiceCollection services, A
3315
options.Application,
3416
options.Key,
3517
options.Environment,
36-
options.CacheExpirationTime,
37-
null,
38-
GetLocalFeatures(options.FeatureToggleCacheConfiguration)
18+
options.CacheExpirationTime
3919
);
4020

4121
manager.StartMonitor();
42-
services.AddSingleton<IFeatureManager>(new FeatureManager(manager));
22+
services.AddSingleton<IAppconfiFeatureManager>(new FeatureManager(manager));
4323

4424
return services;
4525
}

src/Appconfi.Web/FeatureManager.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
namespace Appconfi.Web
22
{
3-
public class FeatureManager : IFeatureManager
3+
public class FeatureManager : IAppconfiFeatureManager
44
{
55
private readonly AppconfiManager manager;
66

77
public FeatureManager(AppconfiManager manager)
88
{
99
this.manager = manager;
1010
}
11-
public bool IsEnabled(string featureName)
11+
public bool IsEnabled(string featureName, bool defaultValue = false)
1212
{
13-
return manager.IsFeatureEnabled(featureName);
13+
return manager.IsFeatureEnabled(featureName, defaultValue);
14+
}
15+
16+
public void ForceRefresh()
17+
{
18+
manager.ForceRefresh();
1419
}
1520
}
1621
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Appconfi.Web
2+
{
3+
public interface IAppconfiFeatureManager
4+
{
5+
void ForceRefresh();
6+
bool IsEnabled(string featureName, bool defaultValue = false);
7+
}
8+
}

src/Appconfi.Web/IFeatureManager.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Appconfi.Web/ResourceHelper.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Appconfi/AppconfiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public string PrepareRequest(string resource)
3636
queryString["env"] = Environment;
3737
queryString["app"] = ApplicationId;
3838

39-
return $"{resource}?{queryString.ToString()}";
39+
return $"{resource}?{queryString}";
4040
}
4141

4242
public string Execute(string resource)

0 commit comments

Comments
 (0)