Skip to content

Commit

Permalink
Merge pull request #281 from dotnetcore/dev
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
catcherwong authored Jan 23, 2021
2 parents 43344bd + 09fc607 commit 5ba82b2
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ jobs:
run: |
for file in nugetpkgs/*.nupkg
do
dotnet nuget push $file -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate -s https://www.nuget.org/api/v2/package
dotnet nuget push $file -k ${{ secrets.MYGET_API_KEY }} --skip-duplicate -s https://www.myget.org/F/ncc/api/v2/package
done
2 changes: 1 addition & 1 deletion Build.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
40 changes: 20 additions & 20 deletions build/version.props
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project>
<PropertyGroup>
<EasyCachingCorePackageVersion>1.1.0</EasyCachingCorePackageVersion>
<EasyCachingMemcachedPackageVersion>1.1.0</EasyCachingMemcachedPackageVersion>
<EasyCachingRedisPackageVersion>1.1.0</EasyCachingRedisPackageVersion>
<EasyCachingSQLitePackageVersion>1.1.0</EasyCachingSQLitePackageVersion>
<EasyCachingInMemoryPackageVersion>1.1.0</EasyCachingInMemoryPackageVersion>
<EasyCachingHybridPackageVersion>1.1.0</EasyCachingHybridPackageVersion>
<EasyCachingAspectCorePackageVersion>1.1.0</EasyCachingAspectCorePackageVersion>
<EasyCachingCastlePackageVersion>1.1.0</EasyCachingCastlePackageVersion>
<EasyCachingResponseCachingPackageVersion>1.1.0</EasyCachingResponseCachingPackageVersion>
<EasyCachingJsonPackageVersion>1.1.0</EasyCachingJsonPackageVersion>
<EasyCachingMessagePackPackageVersion>1.1.0</EasyCachingMessagePackPackageVersion>
<EasyCachingProtobufPackageVersion>1.1.0</EasyCachingProtobufPackageVersion>
<EasyCachingCSRedisPackageVersion>1.1.0</EasyCachingCSRedisPackageVersion>
<EasyCachingRedisBusPackageVersion>1.1.0</EasyCachingRedisBusPackageVersion>
<EasyCachingCSRedisBusPackageVersion>1.1.0</EasyCachingCSRedisBusPackageVersion>
<EasyCachingRabbitBusPackageVersion>1.1.0</EasyCachingRabbitBusPackageVersion>
<EasyCachingDiskPackageVersion>1.1.0</EasyCachingDiskPackageVersion>
<EasyCachingMsExtPackageVersion>1.1.0</EasyCachingMsExtPackageVersion>
<EasyCachingLiteDBPackageVersion>1.1.0</EasyCachingLiteDBPackageVersion>
<EasyCachingSTJsonPackageVersion>1.1.0</EasyCachingSTJsonPackageVersion>
<EasyCachingCorePackageVersion>1.2.0</EasyCachingCorePackageVersion>
<EasyCachingMemcachedPackageVersion>1.2.0</EasyCachingMemcachedPackageVersion>
<EasyCachingRedisPackageVersion>1.2.0</EasyCachingRedisPackageVersion>
<EasyCachingSQLitePackageVersion>1.2.0</EasyCachingSQLitePackageVersion>
<EasyCachingInMemoryPackageVersion>1.2.0</EasyCachingInMemoryPackageVersion>
<EasyCachingHybridPackageVersion>1.2.0</EasyCachingHybridPackageVersion>
<EasyCachingAspectCorePackageVersion>1.2.0</EasyCachingAspectCorePackageVersion>
<EasyCachingCastlePackageVersion>1.2.0</EasyCachingCastlePackageVersion>
<EasyCachingResponseCachingPackageVersion>1.2.0</EasyCachingResponseCachingPackageVersion>
<EasyCachingJsonPackageVersion>1.2.0</EasyCachingJsonPackageVersion>
<EasyCachingMessagePackPackageVersion>1.2.0</EasyCachingMessagePackPackageVersion>
<EasyCachingProtobufPackageVersion>1.2.0</EasyCachingProtobufPackageVersion>
<EasyCachingCSRedisPackageVersion>1.2.0</EasyCachingCSRedisPackageVersion>
<EasyCachingRedisBusPackageVersion>1.2.0</EasyCachingRedisBusPackageVersion>
<EasyCachingCSRedisBusPackageVersion>1.2.0</EasyCachingCSRedisBusPackageVersion>
<EasyCachingRabbitBusPackageVersion>1.2.0</EasyCachingRabbitBusPackageVersion>
<EasyCachingDiskPackageVersion>1.2.0</EasyCachingDiskPackageVersion>
<EasyCachingMsExtPackageVersion>1.2.0</EasyCachingMsExtPackageVersion>
<EasyCachingLiteDBPackageVersion>1.2.0</EasyCachingLiteDBPackageVersion>
<EasyCachingSTJsonPackageVersion>1.2.0</EasyCachingSTJsonPackageVersion>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions bus/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class DefaultCSRedisBus : EasyCachingAbstractBus
/// <param name="clients">Clients.</param>
public DefaultCSRedisBus(IEnumerable<EasyCachingCSRedisClient> clients)
{
this.BusName = "easycachingbus";
this._client = clients.FirstOrDefault(x => x.Name.Equals("easycachingbus"));
}

Expand Down
4 changes: 3 additions & 1 deletion bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ IPooledObjectPolicy<IModel> _objectPolicy
_subConnection = factory.CreateConnection();

_pubChannelPool = new DefaultObjectPool<IModel>(_objectPolicy);

_busId = Guid.NewGuid().ToString("N");

BusName = "easycachingbus";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ public static class EasyCachingOptionsExtensions
/// </summary>
/// <param name="options">Options.</param>
/// <param name="configure">Configure bus settings.</param>
/// <param name="name">name.</param>
public static EasyCachingOptions WithRedisBus(
this EasyCachingOptions options
, Action<RedisBusOptions> configure
, string name = EasyCachingConstValue.DefaultRedisName
)
{
ArgumentCheck.NotNull(configure, nameof(configure));

options.RegisterExtension(new RedisBusOptionsExtension(configure));
options.RegisterExtension(new RedisBusOptionsExtension(name, configure));
return options;
}

Expand All @@ -32,10 +34,12 @@ this EasyCachingOptions options
/// </summary>
/// <param name="options">Options.</param>
/// <param name="configuration">The configuration.</param>
/// <param name="name">The name.</param>
/// <param name="sectionName">The section name in the configuration file.</param>
public static EasyCachingOptions WithRedisBus(
this EasyCachingOptions options
, IConfiguration configuration
, string name = EasyCachingConstValue.DefaultRedisName
, string sectionName = EasyCachingConstValue.RedisBusSection
)
{
Expand All @@ -58,7 +62,7 @@ void configure(RedisBusOptions x)
foreach (var item in redisOptions.Endpoints) x.Endpoints.Add(item);
}

options.RegisterExtension(new RedisBusOptionsExtension(configure));
options.RegisterExtension(new RedisBusOptionsExtension(name, configure));
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public interface IRedisSubscriberProvider
/// </summary>
/// <returns>The subscriber.</returns>
ISubscriber GetSubscriber();

/// <summary>
/// Gets the name of subscriber.
/// </summary>
string SubscriberName { get; }
}
}
5 changes: 5 additions & 0 deletions bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public class RedisBusOptions : BaseRedisOptions
/// </summary>
/// <value>The database.</value>
public int Database { get; set; } = 0;

/// <summary>
/// Gets or sets the serializer name that should be use in this bus.
/// </summary>
public string SerializerName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
using EasyCaching.Core.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

/// <summary>
/// Redis bus options extension.
/// </summary>
internal sealed class RedisBusOptionsExtension : IEasyCachingOptionsExtension
{
/// <summary>
/// The name.
/// </summary>
private readonly string _name;

/// <summary>
/// The configure.
/// </summary>
Expand All @@ -20,9 +27,11 @@ internal sealed class RedisBusOptionsExtension : IEasyCachingOptionsExtension
/// <summary>
/// Initializes a new instance of the <see cref="T:EasyCaching.Bus.Redis.RedisBusOptionsExtension"/> class.
/// </summary>
/// <param name="name">Name.</param>
/// <param name="configure">Configure.</param>
public RedisBusOptionsExtension(Action<RedisBusOptions> configure)
{
public RedisBusOptionsExtension(string name, Action<RedisBusOptions> configure)
{
this._name = name;
this.configure = configure;
}

Expand All @@ -33,11 +42,25 @@ public RedisBusOptionsExtension(Action<RedisBusOptions> configure)
public void AddServices(IServiceCollection services)
{
services.AddOptions();
services.Configure(configure);
services.Configure(_name, configure);

services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
services.TryAddSingleton<IRedisSubscriberProvider, RedisSubscriberProvider>();
services.AddSingleton<IEasyCachingBus, DefaultRedisBus>();
services.AddSingleton<IRedisSubscriberProvider, RedisSubscriberProvider>(x =>
{
var optionsMon = x.GetRequiredService<IOptionsMonitor<RedisBusOptions>>();
var options = optionsMon.Get(_name);
return new RedisSubscriberProvider(_name, options);
});

services.AddSingleton<IEasyCachingBus, DefaultRedisBus>(x =>
{
var subProviders = x.GetServices<IRedisSubscriberProvider>();
var serializers = x.GetServices<IEasyCachingSerializer>();
var optionsMon = x.GetRequiredService<IOptionsMonitor<RedisBusOptions>>();
var options = optionsMon.Get(_name);
var factory = x.GetService<ILoggerFactory>();
return new DefaultRedisBus(_name, subProviders, options, serializers);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace EasyCaching.Bus.Redis
{
using Microsoft.Extensions.Options;
using StackExchange.Redis;
using System;

Expand All @@ -9,6 +8,8 @@
/// </summary>
internal class RedisSubscriberProvider : IRedisSubscriberProvider
{
private readonly string _name;

/// <summary>
/// The options.
/// </summary>
Expand All @@ -22,19 +23,23 @@ internal class RedisSubscriberProvider : IRedisSubscriberProvider
/// <summary>
/// Initializes a new instance of the <see cref="T:EasyCaching.Bus.Redis.RedisSubscriberProvider"/> class.
/// </summary>
/// <param name="name">name.</param>
/// <param name="options">Options.</param>
public RedisSubscriberProvider(IOptions<RedisBusOptions> options)
public RedisSubscriberProvider(string name, RedisBusOptions options)
{
_options = options.Value;
_name = name;
_options = options;
_connectionMultiplexer = new Lazy<ConnectionMultiplexer>(CreateConnectionMultiplexer);
}

public string SubscriberName => _name;

/// <summary>
/// Gets the database connection.
/// </summary>
public ISubscriber GetSubscriber()
{
return _connectionMultiplexer.Value.GetSubscriber();
return _connectionMultiplexer.Value.GetSubscriber();
}

/// <summary>
Expand Down
27 changes: 21 additions & 6 deletions bus/EasyCaching.Bus.Redis/DefaultRedisBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using EasyCaching.Core.Serialization;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -28,17 +30,30 @@ public class DefaultRedisBus : EasyCachingAbstractBus
/// </summary>
private readonly IEasyCachingSerializer _serializer;

/// <summary>
/// The name.
/// </summary>
private readonly string _name;

/// <summary>
/// Initializes a new instance of the <see cref="T:EasyCaching.Bus.Redis.DefaultRedisBus"/> class.
/// </summary>
/// <param name="subscriberProvider">Subscriber provider.</param>
/// <param name="serializer">Serializer.</param>
/// <param name="name">Name.</param>
/// <param name="subscriberProviders">Subscriber provider.</param>
/// <param name="busOptions">bus Options.</param>
/// <param name="serializers">Serializers.</param>
public DefaultRedisBus(
IRedisSubscriberProvider subscriberProvider,
IEasyCachingSerializer serializer)
string name
, IEnumerable<IRedisSubscriberProvider> subscriberProviders
, RedisBusOptions busOptions
, IEnumerable<IEasyCachingSerializer> serializers)
{
this._subscriberProvider = subscriberProvider;
this._serializer = serializer;
this._name = name;
this.BusName = name;
this._subscriberProvider = subscriberProviders.Single(x => x.SubscriberName.Equals(name));
this._serializer = !string.IsNullOrWhiteSpace(busOptions.SerializerName)
? serializers.Single(x => x.Name.Equals(busOptions.SerializerName))
: serializers.Single(x => x.Name.Equals(EasyCachingConstValue.DefaultSerializerName));
this._subscriber = _subscriberProvider.GetSubscriber();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<ProjectReference Include="..\..\src\EasyCaching.HybridCache\EasyCaching.HybridCache.csproj" />
<ProjectReference Include="..\..\serialization\EasyCaching.Serialization.MessagePack\EasyCaching.Serialization.MessagePack.csproj" />
<ProjectReference Include="..\..\src\EasyCaching.Core\EasyCaching.Core.csproj" />
<ProjectReference Include="..\..\bus\EasyCaching.Bus.CSRedis\EasyCaching.Bus.CSRedis.csproj" />
<ProjectReference Include="..\..\bus\EasyCaching.Bus.RabbitMQ\EasyCaching.Bus.RabbitMQ.csproj" />
<ProjectReference Include="..\..\bus\EasyCaching.Bus.Redis\EasyCaching.Bus.Redis.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion sample/EasyCaching.Demo.Providers/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void ConfigureServices(IServiceCollection services)
});

option.UseMemcached(Configuration);

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class DefaultJsonSerializer : IEasyCachingSerializer
/// </summary>
private readonly JsonSerializer jsonSerializer;

/// <summary>
/// default utf-8 encoding
/// </summary>
private static readonly UTF8Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

/// <summary>
/// The name.
/// </summary>
Expand Down Expand Up @@ -48,7 +53,7 @@ public DefaultJsonSerializer(string name, JsonSerializerSettings serializerSetti
public T Deserialize<T>(byte[] bytes)
{
using (var ms = new MemoryStream(bytes))
using (var sr = new StreamReader(ms, Encoding.UTF8))
using (var sr = new StreamReader(ms, s_utf8Encoding))
using (var jtr = new JsonTextReader(sr))
{
return jsonSerializer.Deserialize<T>(jtr);
Expand All @@ -64,7 +69,7 @@ public T Deserialize<T>(byte[] bytes)
public object Deserialize(byte[] bytes, Type type)
{
using (var ms = new MemoryStream(bytes))
using (var sr = new StreamReader(ms, Encoding.UTF8))
using (var sr = new StreamReader(ms, s_utf8Encoding))
using (var jtr = new JsonTextReader(sr))
{
return jsonSerializer.Deserialize(jtr, type);
Expand All @@ -81,7 +86,7 @@ public byte[] Serialize<T>(T value)
{
using (var ms = new MemoryStream())
{
using (var sr = new StreamWriter(ms, Encoding.UTF8))
using (var sr = new StreamWriter(ms, s_utf8Encoding))
using (var jtr = new JsonTextWriter(sr))
{
jsonSerializer.Serialize(jtr, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public object DeserializeObject(ArraySegment<byte> value)
throw new InvalidDataException("JsonTranscoder only supports [\"TypeName\", object]");
}
}

/// <summary>
//; Serialize the specified value.
/// Serialize the specified value.
/// </summary>
/// <returns>The serialize.</returns>
/// <param name="value">Value.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void configure(RedisOptions x)
x.LockMs = redisOptions.LockMs;
x.SleepMs = redisOptions.SleepMs;
x.SerializerName = redisOptions.SerializerName;
x.CacheNulls = redisOptions.CacheNulls;
x.DBConfig = redisOptions.DBConfig;
}

Expand Down
5 changes: 5 additions & 0 deletions src/EasyCaching.Core/Bus/IEasyCachingBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
/// </summary>
public interface IEasyCachingBus : IEasyCachingPublisher , IEasyCachingSubscriber
{
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
string Name { get; }
}
}
2 changes: 2 additions & 0 deletions src/EasyCaching.Core/Bus/NullEasyCachingBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class NullEasyCachingBus : IEasyCachingBus
/// </summary>
public static readonly NullEasyCachingBus Instance = new NullEasyCachingBus();

public string Name => nameof(NullEasyCachingBus);

/// <summary>
/// Releases all resource used by the <see cref="T:EasyCaching.Core.Bus.NullEasyCachingBus"/> object.
/// </summary>
Expand Down
Loading

0 comments on commit 5ba82b2

Please sign in to comment.