Skip to content

Commit 9dd3b7b

Browse files
authored
Merge pull request #228 from akhilesh78/main
Add support for .NET Framework 4.8
2 parents 3b472ff + 79488f4 commit 9dd3b7b

11 files changed

+294
-123
lines changed

src/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,30 @@ public interface IMemcachedClientConfiguration
4949

5050
bool SuppressException { get; }
5151

52+
#if NET5_0_OR_GREATER
5253
SslClientAuthenticationOptions SslClientAuth { get; }
54+
#endif
5355
}
5456
}
5557

5658
#region [ License information ]
59+
5760
/* ************************************************************
58-
*
61+
*
5962
* Copyright (c) 2010 Attila Kisk? enyim.com
60-
*
63+
*
6164
* Licensed under the Apache License, Version 2.0 (the "License");
6265
* you may not use this file except in compliance with the License.
6366
* You may obtain a copy of the License at
64-
*
67+
*
6568
* http://www.apache.org/licenses/LICENSE-2.0
66-
*
69+
*
6770
* Unless required by applicable law or agreed to in writing, software
6871
* distributed under the License is distributed on an "AS IS" BASIS,
6972
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7073
* See the License for the specific language governing permissions and
7174
* limitations under the License.
72-
*
75+
*
7376
* ************************************************************/
74-
#endregion
77+
78+
#endregion

src/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs

+26-12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public MemcachedClientConfiguration(
4343
_logger = loggerFactory.CreateLogger<MemcachedClientConfiguration>();
4444

4545
var options = optionsAccessor.Value;
46+
#if NET5_0_OR_GREATER
4647
if ((options == null || options.Servers.Count == 0) && configuration != null)
4748
{
4849
var section = configuration.GetSection("enyimMemcached");
@@ -56,6 +57,7 @@ public MemcachedClientConfiguration(
5657
options.AddDefaultServer();
5758
}
5859
}
60+
#endif
5961

6062
ConfigureServers(options);
6163

@@ -84,7 +86,8 @@ public MemcachedClientConfiguration(
8486
_logger.LogInformation($"{nameof(SocketPool.QueueTimeout)}: {SocketPool.QueueTimeout}");
8587

8688
SocketPool.ConnectionIdleTimeout = options.SocketPool.ConnectionIdleTimeout;
87-
_logger.LogInformation($"{nameof(SocketPool.ConnectionIdleTimeout)}: {SocketPool.ConnectionIdleTimeout}");
89+
_logger.LogInformation(
90+
$"{nameof(SocketPool.ConnectionIdleTimeout)}: {SocketPool.ConnectionIdleTimeout}");
8891

8992
SocketPool.InitPoolTimeout = options.SocketPool.InitPoolTimeout;
9093

@@ -117,14 +120,17 @@ public MemcachedClientConfiguration(
117120
}
118121
catch (Exception ex)
119122
{
120-
_logger.LogError(new EventId(), ex, $"Unable to load authentication type {options.Authentication.Type}.");
123+
_logger.LogError(new EventId(), ex,
124+
$"Unable to load authentication type {options.Authentication.Type}.");
121125
}
122126
}
123127

124128
UseSslStream = options.UseSslStream;
125129
UseIPv6 = options.UseIPv6;
126130
SuppressException = options.SuppressException;
131+
#if NET5_0_OR_GREATER
127132
SslClientAuth = options.SslClientAuth;
133+
#endif
128134

129135
if (!string.IsNullOrEmpty(options.KeyTransformer))
130136
{
@@ -213,7 +219,10 @@ private void ConfigureServers(MemcachedClientOptions options)
213219
if (!IPAddress.TryParse(server.Address, out var address))
214220
{
215221
address = Dns.GetHostAddresses(server.Address)
216-
.FirstOrDefault(i => i.AddressFamily == (options.UseIPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork));
222+
.FirstOrDefault(i =>
223+
i.AddressFamily == (options.UseIPv6
224+
? AddressFamily.InterNetworkV6
225+
: AddressFamily.InterNetwork));
217226

218227
if (address == null)
219228
{
@@ -339,8 +348,8 @@ IMemcachedNodeLocator IMemcachedClientConfiguration.CreateNodeLocator()
339348
if (f != null) return f.Create();
340349

341350
return NodeLocator == null
342-
? new SingleNodeLocator()
343-
: (IMemcachedNodeLocator)FastActivator.Create(NodeLocator);
351+
? new SingleNodeLocator()
352+
: (IMemcachedNodeLocator)FastActivator.Create(NodeLocator);
344353
}
345354

346355
ITranscoder IMemcachedClientConfiguration.CreateTranscoder()
@@ -352,7 +361,8 @@ IServerPool IMemcachedClientConfiguration.CreatePool()
352361
{
353362
switch (Protocol)
354363
{
355-
case MemcachedProtocol.Text: return new DefaultServerPool(this, new Memcached.Protocol.Text.TextOperationFactory(), _logger);
364+
case MemcachedProtocol.Text:
365+
return new DefaultServerPool(this, new Memcached.Protocol.Text.TextOperationFactory(), _logger);
356366
case MemcachedProtocol.Binary: return new BinaryPool(this, _logger);
357367
}
358368

@@ -362,28 +372,32 @@ IServerPool IMemcachedClientConfiguration.CreatePool()
362372
public bool UseSslStream { get; private set; }
363373
public bool UseIPv6 { get; private set; }
364374
public bool SuppressException { get; private set; }
375+
#if NET5_0_OR_GREATER
365376
public SslClientAuthenticationOptions SslClientAuth { get; private set; }
377+
#endif
366378

367379
#endregion
368380
}
369381
}
370382

371383
#region [ License information ]
384+
372385
/* ************************************************************
373-
*
386+
*
374387
* Copyright (c) 2010 Attila Kisk? enyim.com
375-
*
388+
*
376389
* Licensed under the Apache License, Version 2.0 (the "License");
377390
* you may not use this file except in compliance with the License.
378391
* You may obtain a copy of the License at
379-
*
392+
*
380393
* http://www.apache.org/licenses/LICENSE-2.0
381-
*
394+
*
382395
* Unless required by applicable law or agreed to in writing, software
383396
* distributed under the License is distributed on an "AS IS" BASIS,
384397
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
385398
* See the License for the specific language governing permissions and
386399
* limitations under the License.
387-
*
400+
*
388401
* ************************************************************/
389-
#endregion
402+
403+
#endregion

src/Enyim.Caching/Configuration/MemcachedClientOptions.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public class MemcachedClientOptions : IOptions<MemcachedClientOptions>
2828

2929
public bool SuppressException { get; set; } = true;
3030

31+
#if NET5_0_OR_GREATER
3132
public SslClientAuthenticationOptions SslClientAuth { get; set; }
33+
#endif
3234

3335
public IProviderFactory<IMemcachedNodeLocator> NodeLocatorFactory { get; set; }
3436

@@ -49,8 +51,8 @@ public void AddPlainTextAuthenticator(string zone, string userName, string passw
4951
Parameters = new Dictionary<string, string>
5052
{
5153
{ $"{nameof(zone)}", zone },
52-
{ $"{nameof(userName)}", userName},
53-
{ $"{nameof(password)}", password}
54+
{ $"{nameof(userName)}", userName },
55+
{ $"{nameof(password)}", password }
5456
}
5557
};
5658
}
@@ -79,7 +81,9 @@ public class SocketPoolOptions
7981
public TimeSpan QueueTimeout { get; set; } = new TimeSpan(0, 0, 0, 0, 100);
8082
public TimeSpan ConnectionIdleTimeout { get; set; } = TimeSpan.Zero;
8183
public TimeSpan InitPoolTimeout { get; set; } = new TimeSpan(0, 1, 0);
82-
public INodeFailurePolicyFactory FailurePolicyFactory { get; set; } = new ThrottlingFailurePolicyFactory(5, TimeSpan.FromMilliseconds(2000));
84+
85+
public INodeFailurePolicyFactory FailurePolicyFactory { get; set; } =
86+
new ThrottlingFailurePolicyFactory(5, TimeSpan.FromMilliseconds(2000));
8387

8488
public void CheckPoolSize()
8589
{
@@ -110,4 +114,4 @@ private void CheckTimeout(string paramName, TimeSpan value)
110114
}
111115
}
112116
}
113-
}
117+
}
+38-27
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<Description>EnyimMemcachedCore is a Memcached client library for .NET. Add services.AddEnyimMemcached() in Startup. Inject IMemcachedClient into constructors.</Description>
5-
<Authors>cnblogs.com</Authors>
6-
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
7-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8-
<AssemblyName>EnyimMemcachedCore</AssemblyName>
9-
<PackageId>EnyimMemcachedCore</PackageId>
10-
<PackageReadmeFile>README.md</PackageReadmeFile>
11-
<PackageTags>memcached;cache</PackageTags>
12-
<PackageProjectUrl>https://github.com/cnblogs/EnyimMemcachedCore</PackageProjectUrl>
13-
<RepositoryType>git</RepositoryType>
14-
<RepositoryUrl>https://github.com/cnblogs/EnyimMemcachedCore</RepositoryUrl>
15-
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
16-
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
17-
<LangVersion>latest</LangVersion>
18-
<NoWarn>$(NoWarn);SYSLIB0011</NoWarn>
19-
</PropertyGroup>
3+
<PropertyGroup>
4+
<Description>EnyimMemcachedCore is a Memcached client library for .NET. Add services.AddEnyimMemcached() in Startup. Inject IMemcachedClient into constructors.</Description>
5+
<Authors>cnblogs.com</Authors>
6+
<TargetFrameworks>net6.0;net7.0;net8.0;net48;net481</TargetFrameworks>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
<AssemblyName>EnyimMemcachedCore</AssemblyName>
9+
<PackageId>EnyimMemcachedCore</PackageId>
10+
<PackageReadmeFile>README.md</PackageReadmeFile>
11+
<PackageTags>memcached;cache</PackageTags>
12+
<PackageProjectUrl>https://github.com/cnblogs/EnyimMemcachedCore</PackageProjectUrl>
13+
<RepositoryType>git</RepositoryType>
14+
<RepositoryUrl>https://github.com/cnblogs/EnyimMemcachedCore</RepositoryUrl>
15+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
16+
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
17+
<LangVersion>latest</LangVersion>
18+
<NoWarn>$(NoWarn);SYSLIB0011</NoWarn>
19+
</PropertyGroup>
2020

21-
<ItemGroup>
22-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
23-
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
24-
</ItemGroup>
21+
<ItemGroup Condition="'$(TargetFramework)'!='net48' And '$(TargetFramework)'!='net481'">
22+
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
23+
</ItemGroup>
2524

26-
<ItemGroup>
27-
<PackageReference Include="MessagePack" Version="2.5.140" />
28-
</ItemGroup>
25+
<ItemGroup Condition="'$(TargetFramework)'=='net48' Or '$(TargetFramework)'=='net481'">
26+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
27+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
28+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0"/>
29+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2"/>
30+
<PackageReference Include="System.Net.Security" Version="4.3.2"/>
31+
</ItemGroup>
2932

30-
<ItemGroup>
31-
<None Include="../../README.md" Pack="true" PackagePath="\" />
32-
</ItemGroup>
33+
<ItemGroup>
34+
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2"/>
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<PackageReference Include="MessagePack" Version="2.5.140"/>
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<None Include="../../README.md" Pack="true" PackagePath="\"/>
43+
</ItemGroup>
3344
</Project>

src/Enyim.Caching/EnyimMemcachedApplicationBuilderExtensions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Builder
1212
{
1313
public static class EnyimMemcachedApplicationBuilderExtensions
1414
{
15+
#if NET5_0_OR_GREATER
1516
public static IApplicationBuilder UseEnyimMemcached(this IApplicationBuilder app)
1617
{
1718
var logger = app.ApplicationServices.GetService<ILogger<IMemcachedClient>>();
@@ -27,5 +28,6 @@ public static IApplicationBuilder UseEnyimMemcached(this IApplicationBuilder app
2728

2829
return app;
2930
}
31+
#endif
3032
}
31-
}
33+
}

src/Enyim.Caching/EnyimMemcachedServiceCollectionExtensions.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Extensions.DependencyInjection
1414
{
1515
public static class EnyimMemcachedServiceCollectionExtensions
1616
{
17+
#if NET5_0_OR_GREATER
1718
public static IServiceCollection AddEnyimMemcached(
1819
this IServiceCollection services,
1920
string sectionKey = "enyimMemcached",
@@ -32,6 +33,7 @@ public static IServiceCollection AddEnyimMemcached(
3233
return services.AddEnyimMemcachedInternal(
3334
s => s.AddOptions<MemcachedClientOptions>().BindConfiguration(sectionKey), asDistributedCache);
3435
}
36+
#endif
3537

3638
public static IServiceCollection AddEnyimMemcached(
3739
this IServiceCollection services,
@@ -52,6 +54,7 @@ public static IServiceCollection AddEnyimMemcached(
5254
s => s.Configure(setupAction), asDistributedCache);
5355
}
5456

57+
#if NET5_0_OR_GREATER
5558
public static IServiceCollection AddEnyimMemcached(
5659
this IServiceCollection services,
5760
IConfigurationSection configurationSection,
@@ -92,6 +95,7 @@ public static IServiceCollection AddEnyimMemcached(
9295
return services.AddEnyimMemcachedInternal(
9396
s => s.Configure<MemcachedClientOptions>(section), asDistributedCache);
9497
}
98+
#endif
9599

96100
private static IServiceCollection AddEnyimMemcachedInternal(
97101
this IServiceCollection services,
@@ -115,6 +119,7 @@ private static IServiceCollection AddEnyimMemcachedInternal(
115119
return services;
116120
}
117121

122+
#if NET5_0_OR_GREATER
118123
public static IServiceCollection AddEnyimMemcached<T>(
119124
this IServiceCollection services,
120125
string sectionKey)
@@ -149,12 +154,13 @@ public static IServiceCollection AddEnyimMemcached<T>(
149154
}
150155

151156
return services.AddEnyimMemcached<T>(
152-
s => s.Configure<MemcachedClientOptions>(configuration.GetSection(sectionKey)));
157+
s => s.Configure<MemcachedClientOptions>(configuration.GetSection(sectionKey)));
153158
}
159+
#endif
154160

155161
public static IServiceCollection AddEnyimMemcached<T>(
156-
this IServiceCollection services,
157-
Action<IServiceCollection> configure)
162+
this IServiceCollection services,
163+
Action<IServiceCollection> configure)
158164
{
159165
services.AddOptions();
160166
configure?.Invoke(services);
@@ -173,4 +179,4 @@ public static IServiceCollection AddEnyimMemcached<T>(
173179
return services;
174180
}
175181
}
176-
}
182+
}

0 commit comments

Comments
 (0)