Skip to content

Commit a78ffcb

Browse files
Added support for .NET Framework 4.8
1 parent 073b055 commit a78ffcb

10 files changed

+234
-94
lines changed

src/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs

Lines changed: 10 additions & 6 deletions
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/MemcachedClientOptions.cs

Lines changed: 8 additions & 4 deletions
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
}
@@ -80,7 +82,9 @@ public class SocketPoolOptions
8082
public TimeSpan QueueTimeout { get; set; } = new TimeSpan(0, 0, 0, 0, 100);
8183
public TimeSpan ConnectionIdleTimeout { get; set; } = TimeSpan.Zero;
8284
public TimeSpan InitPoolTimeout { get; set; } = new TimeSpan(0, 1, 0);
83-
public INodeFailurePolicyFactory FailurePolicyFactory { get; set; } = new ThrottlingFailurePolicyFactory(5, TimeSpan.FromMilliseconds(2000));
85+
86+
public INodeFailurePolicyFactory FailurePolicyFactory { get; set; } =
87+
new ThrottlingFailurePolicyFactory(5, TimeSpan.FromMilliseconds(2000));
8488

8589
public void CheckPoolSize()
8690
{
@@ -112,4 +116,4 @@ private void CheckTimeout(string paramName, TimeSpan value)
112116
}
113117
}
114118
}
115-
}
119+
}

src/Enyim.Caching/Enyim.Caching.csproj

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,27 @@
2828
</PackageReleaseNotes>
2929
</PropertyGroup>
3030

31-
<ItemGroup>
32-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
33-
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
34-
</ItemGroup>
31+
<ItemGroup Condition="'$(TargetFramework)'!='net48' And '$(TargetFramework)'!='net481'">
32+
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
33+
</ItemGroup>
3534

36-
<ItemGroup>
37-
<PackageReference Include="MessagePack" Version="2.5.140" />
38-
</ItemGroup>
35+
<ItemGroup Condition="'$(TargetFramework)'=='net48' Or '$(TargetFramework)'=='net481'">
36+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
37+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
38+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0"/>
39+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2"/>
40+
<PackageReference Include="System.Net.Security" Version="4.3.2"/>
41+
</ItemGroup>
3942

40-
<ItemGroup>
41-
<None Include="../../README.md" Pack="true" PackagePath="\" />
42-
</ItemGroup>
43+
<ItemGroup>
44+
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2"/>
45+
</ItemGroup>
46+
47+
<ItemGroup>
48+
<PackageReference Include="MessagePack" Version="2.5.140"/>
49+
</ItemGroup>
50+
51+
<ItemGroup>
52+
<None Include="../../README.md" Pack="true" PackagePath="\"/>
53+
</ItemGroup>
4354
</Project>

src/Enyim.Caching/EnyimMemcachedApplicationBuilderExtensions.cs

Lines changed: 3 additions & 1 deletion
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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection
1515
{
1616
public static class EnyimMemcachedServiceCollectionExtensions
1717
{
18+
#if NET5_0_OR_GREATER
1819
public static IServiceCollection AddEnyimMemcached(
1920
this IServiceCollection services,
2021
string sectionKey = "enyimMemcached",
@@ -33,6 +34,7 @@ public static IServiceCollection AddEnyimMemcached(
3334
return services.AddEnyimMemcachedInternal(
3435
s => s.AddOptions<MemcachedClientOptions>().BindConfiguration(sectionKey), asDistributedCache);
3536
}
37+
#endif
3638

3739
public static IServiceCollection AddEnyimMemcached(
3840
this IServiceCollection services,
@@ -53,6 +55,7 @@ public static IServiceCollection AddEnyimMemcached(
5355
s => s.Configure(setupAction), asDistributedCache);
5456
}
5557

58+
#if NET5_0_OR_GREATER
5659
public static IServiceCollection AddEnyimMemcached(
5760
this IServiceCollection services,
5861
IConfigurationSection configurationSection,
@@ -93,6 +96,7 @@ public static IServiceCollection AddEnyimMemcached(
9396
return services.AddEnyimMemcachedInternal(
9497
s => s.Configure<MemcachedClientOptions>(section), asDistributedCache);
9598
}
99+
#endif
96100

97101
private static IServiceCollection AddEnyimMemcachedInternal(
98102
this IServiceCollection services,
@@ -116,6 +120,7 @@ private static IServiceCollection AddEnyimMemcachedInternal(
116120
return services;
117121
}
118122

123+
#if NET5_0_OR_GREATER
119124
public static IServiceCollection AddEnyimMemcached<T>(
120125
this IServiceCollection services,
121126
string sectionKey)
@@ -150,12 +155,13 @@ public static IServiceCollection AddEnyimMemcached<T>(
150155
}
151156

152157
return services.AddEnyimMemcached<T>(
153-
s => s.Configure<MemcachedClientOptions>(configuration.GetSection(sectionKey)));
158+
s => s.Configure<MemcachedClientOptions>(configuration.GetSection(sectionKey)));
154159
}
160+
#endif
155161

156162
public static IServiceCollection AddEnyimMemcached<T>(
157-
this IServiceCollection services,
158-
Action<IServiceCollection> configure)
163+
this IServiceCollection services,
164+
Action<IServiceCollection> configure)
159165
{
160166
services.AddOptions();
161167
configure?.Invoke(services);
@@ -174,4 +180,4 @@ public static IServiceCollection AddEnyimMemcached<T>(
174180
return services;
175181
}
176182
}
177-
}
183+
}

src/Enyim.Caching/Memcached/DefaultServerPool.cs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ public DefaultServerPool(
4848

4949
~DefaultServerPool()
5050
{
51-
try { ((IDisposable)this).Dispose(); }
52-
catch { }
51+
try
52+
{
53+
((IDisposable)this).Dispose();
54+
}
55+
catch
56+
{
57+
}
5358
}
5459

5560
protected virtual IMemcachedNode CreateNode(EndPoint endpoint)
@@ -156,7 +161,8 @@ private void NodeFail(IMemcachedNode node)
156161
{
157162
if (_isDisposed)
158163
{
159-
if (_logger.IsEnabled(LogLevel.Warning)) _logger.LogWarning("Got a node fail but the pool is already disposed. Ignoring.");
164+
if (_logger.IsEnabled(LogLevel.Warning))
165+
_logger.LogWarning("Got a node fail but the pool is already disposed. Ignoring.");
160166

161167
return;
162168
}
@@ -210,15 +216,13 @@ IEnumerable<IMemcachedNode> IServerPool.GetWorkingNodes()
210216

211217
void IServerPool.Start()
212218
{
213-
_allNodes = _configuration.Servers.
214-
Select(ep =>
215-
{
216-
var node = CreateNode(ep);
217-
node.Failed += NodeFail;
219+
_allNodes = _configuration.Servers.Select(ep =>
220+
{
221+
var node = CreateNode(ep);
222+
node.Failed += NodeFail;
218223

219-
return node;
220-
}).
221-
ToArray();
224+
return node;
225+
}).ToArray();
222226

223227
// initialize the locator
224228
var locator = _configuration.CreateNodeLocator();
@@ -234,6 +238,7 @@ event Action<IMemcachedNode> IServerPool.NodeFailed
234238
}
235239

236240
#endregion
241+
237242
#region [ IDisposable ]
238243

239244
void IDisposable.Dispose()
@@ -250,14 +255,26 @@ void IDisposable.Dispose()
250255
// the nodes one last time
251256
var nd = _nodeLocator as IDisposable;
252257
if (nd != null)
253-
try { nd.Dispose(); }
254-
catch (Exception e) { _logger.LogError(nameof(DefaultServerPool), e); }
258+
try
259+
{
260+
nd.Dispose();
261+
}
262+
catch (Exception e)
263+
{
264+
_logger.LogError(nameof(DefaultServerPool), e);
265+
}
255266

256267
_nodeLocator = null;
257268

258269
for (var i = 0; i < _allNodes.Length; i++)
259-
try { _allNodes[i].Dispose(); }
260-
catch (Exception e) { _logger.LogError(nameof(DefaultServerPool), e); }
270+
try
271+
{
272+
_allNodes[i].Dispose();
273+
}
274+
catch (Exception e)
275+
{
276+
_logger.LogError(nameof(DefaultServerPool), e);
277+
}
261278

262279
// stop the timer
263280
if (_resurrectTimer != null)
@@ -274,21 +291,23 @@ void IDisposable.Dispose()
274291
}
275292

276293
#region [ License information ]
294+
277295
/* ************************************************************
278-
*
296+
*
279297
* Copyright (c) 2010 Attila Kisk? enyim.com
280-
*
298+
*
281299
* Licensed under the Apache License, Version 2.0 (the "License");
282300
* you may not use this file except in compliance with the License.
283301
* You may obtain a copy of the License at
284-
*
302+
*
285303
* http://www.apache.org/licenses/LICENSE-2.0
286-
*
304+
*
287305
* Unless required by applicable law or agreed to in writing, software
288306
* distributed under the License is distributed on an "AS IS" BASIS,
289307
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
290308
* See the License for the specific language governing permissions and
291309
* limitations under the License.
292-
*
310+
*
293311
* ************************************************************/
294-
#endregion
312+
313+
#endregion

0 commit comments

Comments
 (0)