8000 Added support for .NET Framework 4.8 by akhilesh78 · Pull Request #228 · cnblogs/EnyimMemcachedCore · GitHub
[go: up one dir, main page]

Skip to content

Added support for .NET Framework 4.8 #228

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

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
16 changes: 10 additions & 6 deletions src/Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,30 @@ public interface IMemcachedClientConfiguration

bool SuppressException { get; }

#if NET5_0_OR_GREATER
SslClientAuthenticationOptions SslClientAuth { get; }
#endif
}
}

#region [ License information ]

/* ************************************************************
*
*
* Copyright (c) 2010 Attila Kisk? enyim.com
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* ************************************************************/
#endregion

#endregion
38 changes: 26 additions & 12 deletions src/Enyim.Caching/Configuration/MemcachedClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public MemcachedClientConfiguration(
_logger = loggerFactory.CreateLogger<MemcachedClientConfiguration>();

var options = optionsAccessor.Value;
#if NET5_0_OR_GREATER
if ((options == null || options.Servers.Count == 0) && configuration != null)
{
var section = configuration.GetSection("enyimMemcached");
Expand All @@ -56,6 +57,7 @@ public MemcachedClientConfiguration(
options.AddDefaultServer();
}
}
#endif

ConfigureServers(options);

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

SocketPool.ConnectionIdleTimeout = options.SocketPool.ConnectionIdleTimeout;
_logger.LogInformation($"{nameof(SocketPool.ConnectionIdleTimeout)}: {SocketPool.ConnectionIdleTimeout}");
_logger.LogInformation(
$"{nameof(SocketPool.ConnectionIdleTimeout)}: {SocketPool.ConnectionIdleTimeout}");

SocketPool.InitPoolTimeout = options.SocketPool.InitPoolTimeout;

Expand Down Expand Up @@ -117,14 +120,17 @@ public MemcachedClientConfiguration(
}
catch (Exception ex)
{
_logger.LogError(new EventId(), ex, $"Unable to load authentication type {options.Authentication.Type}.");
_logger.LogError(new EventId(), ex,
$"Unable to load authentication type {options.Authentication.Type}.");
}
}

UseSslStream = options.UseSslStream;
UseIPv6 = options.UseIPv6;
SuppressException = options.SuppressException;
#if NET5_0_OR_GREATER
SslClientAuth = options.SslClientAuth;
#endif

if (!string.IsNullOrEmpty(options.KeyTransformer))
{
Expand Down Expand Up @@ -213,7 +219,10 @@ private void ConfigureServers(MemcachedClientOptions options)
if (!IPAddress.TryParse(server.Address, out var address))
{
address = Dns.GetHostAddresses(server.Address)
.FirstOrDefault(i => i.AddressFamily == (options.UseIPv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork));
.FirstOrDefault(i =>
i.AddressFamily == (options.UseIPv6
? AddressFamily.InterNetworkV6
: AddressFamily.InterNetwork));

if (address == null)
{
Expand Down Expand Up @@ -339,8 +348,8 @@ IMemcachedNodeLocator IMemcachedClientConfiguration.CreateNodeLocator()
if (f != null) return f.Create();

return NodeLocator == null
? new SingleNodeLocator()
: (IMemcachedNodeLocator)FastActivator.Create(NodeLocator);
? new SingleNodeLocator()
: (IMemcachedNodeLocator)FastActivator.Create(NodeLocator);
}

ITranscoder IMemcachedClientConfiguration.CreateTranscoder()
Expand All @@ -352,7 +361,8 @@ IServerPool IMemcachedClientConfiguration.CreatePool()
{
switch (Protocol)
{
case MemcachedProtocol.Text: return new DefaultServerPool(this, new Memcached.Protocol.Text.TextOperationFactory(), _logger);
case MemcachedProtocol.Text:
return new DefaultServerPool(this, new Memcached.Protocol.Text.TextOperationFactory(), _logger);
case MemcachedProtocol.Binary: return new BinaryPool(this, _logger);
}

Expand All @@ -362,28 +372,32 @@ IServerPool IMemcachedClientConfiguration.CreatePool()
public bool UseSslStream { get; private set; }
public bool UseIPv6 { get; private set; }
public bool SuppressException { get; private set; }
#if NET5_0_OR_GREATER
public SslClientAuthenticationOptions SslClientAuth { get; private set; }
#endif

#endregion
}
}

#region [ License information ]

/* ************************************************************
*
*
* Copyright (c) 2010 Attila Kisk? enyim.com
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* ************************************************************/
#endregion

#endregion
12 changes: 8 additions & 4 deletions src/Enyim.Caching/Configuration/MemcachedClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class MemcachedClientOptions : IOptions<MemcachedClientOptions>

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

#if NET5_0_OR_GREATER
public SslClientAuthenticationOptions SslClientAuth { get; set; }
#endif

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

Expand All @@ -49,8 +51,8 @@ public void AddPlainTextAuthenticator(string zone, string userName, string passw
Parameters = new Dictionary<string, string>
{
{ $"{nameof(zone)}", zone },
{ $"{nameof(userName)}", userName},
67ED { $"{nameof(password)}", password}
{ $"{nameof(userName)}", userName },
{ $"{nameof(password)}", password }
}
};
}
Expand Down Expand Up @@ -79,7 +81,9 @@ public class SocketPoolOptions
public TimeSpan QueueTimeout { get; set; } = new TimeSpan(0, 0, 0, 0, 100);
public TimeSpan ConnectionIdleTimeout { get; set; } = TimeSpan.Zero;
public TimeSpan InitPoolTimeout { get; set; } = new TimeSpan(0, 1, 0);
public INodeFailurePolicyFactory FailurePolicyFactory { get; set; } = new ThrottlingFailurePolicyFactory(5, TimeSpan.FromMilliseconds(2000));

public INodeFailurePolicyFactory FailurePolicyFactory { get; set; } =
new ThrottlingFailurePolicyFactory(5, TimeSpan.FromMilliseconds(2000));

public void CheckPoolSize()
{
Expand Down Expand Up @@ -110,4 +114,4 @@ private void CheckTimeout(string paramName, TimeSpan value)
}
}
}
}
}
65 changes: 38 additions & 27 deletions src/Enyim.Caching/Enyim.Caching.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>EnyimMemcachedCore is a Memcached client library for .NET. Add services.AddEnyimMemcached() in Startup. Inject IMemcachedClient into constructors.</Description>
<Authors>cnblogs.com</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>EnyimMemcachedCore</AssemblyName>
<PackageId>EnyimMemcachedCore</PackageId>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>memcached;cache</PackageTags>
<PackageProjectUrl>https://github.com/cnblogs/EnyimMemcachedCore</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/cnblogs/EnyimMemcachedCore</RepositoryUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);SYSLIB0011</NoWarn>
</PropertyGroup>
<PropertyGroup>
<Description>EnyimMemcachedCore is a Memcached client library for .NET. Add services.AddEnyimMemcached() in Startup. Inject IMemcachedClient into constructors.</Description>
<Authors>cnblogs.com</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0;net48;net481</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>EnyimMemcachedCore</AssemblyName>
<PackageId>EnyimMemcachedCore</PackageId>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>memcached;cache</PackageTags>
<PackageProjectUrl>https://github.com/cnblogs/EnyimMemcachedCore</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/cnblogs/EnyimMemcachedCore</RepositoryUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);SYSLIB0011</NoWarn>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="MessagePack" Version="2.5.140" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net48' Or '$(TargetFramework)'=='net481'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2"/>
<PackageReference Include="System.Net.Security" Version="4.3.2"/>
</ItemGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="MessagePack" Version="2.5.140"/>
</ItemGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Builder
{
public static class EnyimMemcachedApplicationBuilderExtensions
{
#if NET5_0_OR_GREATER
public static IApplicationBuilder UseEnyimMemcached(this IApplicationBuilder app)
{
var logger = app.ApplicationServices.GetService<ILogger<IMemcachedClient>>();
Expand All @@ -27,5 +28,6 @@ public static IApplicationBuilder UseEnyimMemcached(this IApplicationBuilder app

return app;
}
#endif
}
}
}
14 changes: 10 additions & 4 deletions src/Enyim.Caching/EnyimMemcachedServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class EnyimMemcachedServiceCollectionExtensions
{
#if NET5_0_OR_GREATER
public static IServiceCollection AddEnyimMemcached(
this IServiceCollection services,
string sectionKey = "enyimMemcached",
Expand All @@ -32,6 +33,7 @@ public static IServiceCollection AddEnyimMemcached(
return services.AddEnyimMemcachedInternal(
s => s.AddOptions<MemcachedClientOptions>().BindConfiguration(sectionKey), asDistributedCache);
}
#endif

public static IServiceCollection AddEnyimMemcached(
this IServiceCollection services,
Expand All @@ -52,6 +54,7 @@ public static IServiceCollection AddEnyimMemcached(
s => s.Configure(setupAction), asDistributedCache);
}

#if NET5_0_OR_GREATER
public static IServiceCollection AddEnyimMemcached(
this IServiceCollection services,
IConfigurationSection configurationSection,
Expand Down Expand Up @@ -92,6 +95,7 @@ public static IServiceCollection AddEnyimMemcached(
return services.AddEnyimMemcachedInternal(
s => s.Configure<MemcachedClientOptions>(section), asDistributedCache);
}
#endif

private static IServiceCollection AddEnyimMemcachedInternal(
this IServiceCollection services,
Expand All @@ -115,6 +119,7 @@ private static IServiceCollection AddEnyimMemcachedInternal(
return services;
}

#if NET5_0_OR_GREATER
public static IServiceCollection AddEnyimMemcached<T>(
this IServiceCollection services,
string sectionKey)
Expand Down Expand Up @@ -149,12 +154,13 @@ public static IServiceCollection AddEnyimMemcached<T>(
}

return services.AddEnyimMemcached<T>(
s => s.Configure<MemcachedClientOptions>(configuration.GetSection(sectionKey)));
s => s.Configure<MemcachedClientOptions>(configuration.GetSection(sectionKey)));
}
#endif

public static IServiceCollection AddEnyimMemcached<T>(
this IServiceCollection services,
Action<IServiceCollection> configure)
this IServiceCollection services,
Action<IServiceCollection> configure)
{
services.AddOptions();
configure?.Invoke(services);
Expand All @@ -173,4 +179,4 @@ public static IServiceCollection AddEnyimMemcached<T>(
return services;
}
}
}
}
Loading
Loading
0