Skip to content

Commit 52f2250

Browse files
author
Chris Young
committed
Merge tag '5.0.0' into develop
5.0.0 5.0.0
2 parents 1ed7748 + d711836 commit 52f2250

File tree

67 files changed

+1628
-1026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1628
-1026
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ paket-files/
251251
.idea/
252252
*.sln.iml
253253
tools
254-
VersionAssemblyInfo.cs
255254
.dotnet
256255
tools/*
257256
!tools/packages.config

ArchitectNow.Framework.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Redis", "Redis", "{EC725C51
2727
EndProject
2828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchitectNow.Redis", "src\ArchitectNow.Redis\ArchitectNow.Redis.csproj", "{471C73F4-D1AA-4D32-89A9-877E3F05633C}"
2929
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchitectNow.Caching", "src\ArchitectNow.Caching\ArchitectNow.Caching.csproj", "{23A4DB74-55C7-4447-A216-4ECC6CFFABD6}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -65,6 +67,10 @@ Global
6567
{471C73F4-D1AA-4D32-89A9-877E3F05633C}.Debug|Any CPU.Build.0 = Debug|Any CPU
6668
{471C73F4-D1AA-4D32-89A9-877E3F05633C}.Release|Any CPU.ActiveCfg = Release|Any CPU
6769
{471C73F4-D1AA-4D32-89A9-877E3F05633C}.Release|Any CPU.Build.0 = Release|Any CPU
70+
{23A4DB74-55C7-4447-A216-4ECC6CFFABD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71+
{23A4DB74-55C7-4447-A216-4ECC6CFFABD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
72+
{23A4DB74-55C7-4447-A216-4ECC6CFFABD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
73+
{23A4DB74-55C7-4447-A216-4ECC6CFFABD6}.Release|Any CPU.Build.0 = Release|Any CPU
6874
EndGlobalSection
6975
GlobalSection(SolutionProperties) = preSolution
7076
HideSolutionNode = FALSE
@@ -78,5 +84,6 @@ Global
7884
{BC311746-D050-4993-AF5B-65A465C02E9B} = {00A56DCD-AEA5-40E4-AE57-046E684ECC1D}
7985
{B7AF1D06-A890-4663-9610-68E19086CC73} = {EC725C51-075F-434C-AFFD-9B8D7A953604}
8086
{471C73F4-D1AA-4D32-89A9-877E3F05633C} = {EC725C51-075F-434C-AFFD-9B8D7A953604}
87+
{23A4DB74-55C7-4447-A216-4ECC6CFFABD6} = {00A56DCD-AEA5-40E4-AE57-046E684ECC1D}
8188
EndGlobalSection
8289
EndGlobal

GitVersion.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mode: ContinuousDeployment
2+
branches: {}
3+
ignore:
4+
sha: []

VersionAssemblyInfo.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Cake.
4+
// </auto-generated>
5+
//------------------------------------------------------------------------------
6+
using System.Reflection;
7+
8+
[assembly: AssemblyVersion("1.2.0.0")]
9+
[assembly: AssemblyFileVersion("1.2.0.0")]
10+
[assembly: AssemblyInformationalVersion("1.2.0-alpha.39+Branch.develop.Sha.e8c9560d896e6d9278fa3302bf7cabf6330cef9d")]
11+

build.cake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ Task("DotNet-MsBuild")
147147
.WithProperty("TreatWarningsAsErrors", treatWarningsAsErrors)
148148
.WithTarget("Build")
149149
);
150+
151+
MSBuild("src/ArchitectNow.Caching/ArchitectNow.Caching.csproj", c => c
152+
.SetConfiguration(configuration)
153+
.SetVerbosity(Verbosity.Minimal)
154+
.UseToolVersion(MSBuildToolVersion.VS2017)
155+
.WithProperty("TreatWarningsAsErrors", treatWarningsAsErrors)
156+
.WithProperty("AssemblyVersion")
157+
.WithTarget("Build")
158+
);
150159

151160
MSBuild("src/ArchitectNow.Web/ArchitectNow.Web.csproj", c => c
152161
.SetConfiguration(configuration)
@@ -228,6 +237,15 @@ Task("DotNet-MsBuild-Pack")
228237
.WithProperty("IncludeSymbols", includeSymbols)
229238
.WithTarget("Pack"));
230239

240+
MSBuild("src/ArchitectNow.Caching/ArchitectNow.Caching.csproj", c => c
241+
.SetConfiguration(configuration)
242+
.SetVerbosity(Verbosity.Normal)
243+
.UseToolVersion(MSBuildToolVersion.VS2017)
244+
.WithProperty("PackageVersion", versionInfo.NuGetVersionV2)
245+
.WithProperty("NoBuild", "true")
246+
.WithProperty("IncludeSymbols", includeSymbols)
247+
.WithTarget("Pack"));
248+
231249
//Mongo
232250
MSBuild("src/ArchitectNow.Mongo/ArchitectNow.Mongo.csproj", c => c
233251
.SetConfiguration(configuration)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
4+
<Authors>ArchitectNow</Authors>
5+
<Company>ArchitectNow</Company>
6+
<Product>ArchitectNow.Caching</Product>
7+
<PackageId>ArchitectNow.Caching</PackageId>
8+
<PackageProjectUrl>https://github.com/ArchitectNow/ArchitectNow.Framework</PackageProjectUrl>
9+
<PackageIconUrl>https://secure.gravatar.com/avatar/83fed82c32dc5424b4245cfc03d57b39?s=32&amp;r=g&amp;d=retro</PackageIconUrl>
10+
<RepositoryUrl>https://github.com/ArchitectNow/ArchitectNow.Framework</RepositoryUrl>
11+
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
12+
<Copyright>Copyright © 2014-2018 ArchitectNow</Copyright>
13+
<PackageLicenseUrl>https://github.com/ArchitectNow/ArchitectNow.Framework/blob/master/LICENSE</PackageLicenseUrl>
14+
<Description>ArchitectNow Framework - Models</Description>
15+
</PropertyGroup>
16+
<PropertyGroup>
17+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
18+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
19+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
20+
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<PackageReference Include="Autofac" Version="4.8.0" />
24+
<PackageReference Include="CacheManager.Serialization.Json" Version="1.1.2" />
25+
<PackageReference Include="CacheManager.StackExchange.Redis" Version="1.1.2" />
26+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.1" />
28+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.1" />
29+
<PackageReference Include="NETStandard.Library" Version="2.0.2" />
30+
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
31+
</ItemGroup>
32+
<ItemGroup>
33+
<Compile Include="..\..\VersionAssemblyInfo.cs" Link="VersionAssemblyInfo.cs" />
34+
</ItemGroup>
35+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace ArchitectNow.Caching
5+
{
6+
static class AsyncExtensions
7+
{
8+
public static Task<T> AsResult<T>(this T result)
9+
{
10+
return Task.FromResult(result);
11+
}
12+
13+
public static Task Invoke(this Action action)
14+
{
15+
return Task.Run(action);
16+
}
17+
}
18+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using CacheManager.Core;
3+
using Microsoft.Extensions.Logging;
4+
using Microsoft.Extensions.Options;
5+
using Newtonsoft.Json;
6+
using StackExchange.Redis;
7+
8+
namespace ArchitectNow.Caching
9+
{
10+
class CacheKeeper<T> : ICacheKeeper<T>
11+
{
12+
private readonly ILogger<CacheKeeper<T>> _log;
13+
private readonly ICacheManager<T> _distributed;
14+
private readonly ICacheManager<T> _inMemory;
15+
private bool _distributedEnabled = true;
16+
private readonly RedisOptions _redisOptions;
17+
18+
public CacheKeeper(ILogger<CacheKeeper<T>> log, IOptions<RedisOptions> redisOptions, IOptions<CachingOptions> cachingOptions)
19+
{
20+
_log = log;
21+
_redisOptions = redisOptions.Value;
22+
23+
if (!cachingOptions.Value.Enabled)
24+
{
25+
_distributedEnabled = false;
26+
_inMemory = CacheFactory.Build<T>(s => s.WithHandle(typeof(NoOpCacheHandler<>), Guid.NewGuid().ToString("N")));
27+
return;
28+
}
29+
30+
_inMemory = CacheFactory.Build<T>(
31+
s => s
32+
.WithDictionaryHandle()
33+
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(5)));
34+
35+
var multiplexer = Create();
36+
37+
if (multiplexer == null)
38+
{
39+
_distributedEnabled = false;
40+
return;
41+
}
42+
43+
multiplexer.ConnectionFailed += (sender, args) =>
44+
{
45+
_distributedEnabled = false;
46+
47+
_log.LogDebug("Connection failed, disabling redis...");
48+
};
49+
50+
multiplexer.ConnectionRestored += (sender, args) =>
51+
{
52+
_distributedEnabled = true;
53+
54+
_log.LogDebug("Connection restored, redis is back...");
55+
};
56+
57+
var jsonSerializerSettings = new JsonSerializerSettings
58+
{
59+
Formatting = Formatting.None
60+
};
61+
62+
_distributed = CacheFactory.Build<T>(
63+
s =>
64+
{
65+
s
66+
.WithJsonSerializer(jsonSerializerSettings, jsonSerializerSettings)
67+
.WithDictionaryHandle()
68+
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMinutes(30))
69+
.And
70+
.WithRedisConfiguration("redis", multiplexer)
71+
.WithRedisCacheHandle("redis");
72+
});
73+
}
74+
75+
public ICacheManager<T> GetCacheManager()
76+
{
77+
if (_distributedEnabled && _distributed != null)
78+
{
79+
return _distributed;
80+
}
81+
82+
return _inMemory;
83+
}
84+
85+
private IConnectionMultiplexer Create()
86+
{
87+
var isEnabled = _redisOptions.Enabled;
88+
89+
if (!isEnabled)
90+
{
91+
return null;
92+
}
93+
94+
var connectionString = _redisOptions.ConnectionString;
95+
96+
if (string.IsNullOrEmpty(connectionString))
97+
{
98+
throw new Exception("Missing redis connection string.");
99+
}
100+
101+
var configurationOptions = ConfigurationOptions.Parse(connectionString);
102+
103+
try
104+
{
105+
return ConnectionMultiplexer.Connect(configurationOptions);
106+
}
107+
catch (Exception exception)
108+
{
109+
_log.LogError(exception.Message);
110+
return null;
111+
}
112+
}
113+
}
114+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Autofac;
2+
using CacheManager.Core;
3+
4+
namespace ArchitectNow.Caching
5+
{
6+
class CacheMangerFactory : ICacheMangerFactory
7+
{
8+
private readonly IComponentContext _context;
9+
10+
public CacheMangerFactory(IComponentContext context)
11+
{
12+
_context = context;
13+
}
14+
15+
public ICacheManager<T> Resolve<T>()
16+
{
17+
var cacheManager = _context.Resolve<ICacheKeeper<T>>().GetCacheManager();
18+
19+
return cacheManager;
20+
}
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Autofac;
2+
using Microsoft.Extensions.Configuration;
3+
4+
namespace ArchitectNow.Caching
5+
{
6+
public class CachingModule : Module
7+
{
8+
protected override void Load(ContainerBuilder builder)
9+
{
10+
builder.RegisterType<CachingRegion>().As<ICachingRegion>().SingleInstance();
11+
builder.RegisterType<CachingService>().As<ICachingService>().SingleInstance();
12+
builder.RegisterType<CacheMangerFactory>().As<ICacheMangerFactory>().SingleInstance();
13+
builder.RegisterGeneric(typeof(CacheKeeper<>)).As(typeof(ICacheKeeper<>)).SingleInstance();
14+
15+
builder.Register(context => context.Resolve<IConfiguration>().CreateOptions<RedisOptions>("redis")).AsSelf().SingleInstance();
16+
17+
builder.Register(context => context.Resolve<IConfiguration>().CreateOptions<CachingOptions>("caching")).AsSelf().SingleInstance();
18+
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)