From 53b99166e2d574d8c2d5b491aa7e3b0562ba0327 Mon Sep 17 00:00:00 2001 From: haiduong87 Date: Sat, 21 Nov 2020 16:36:03 +0700 Subject: [PATCH 01/11] Update DefaultSQLiteCachingProvider.cs Follow https://github.com/dotnetcore/EasyCaching/commit/db73e8f875079cbbe03c8a6417c6dce045c42e90 We need to update this file too. --- src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs index f5e3b427..20a12b8a 100644 --- a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs +++ b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs @@ -31,7 +31,7 @@ public partial class DefaultSQLiteCachingProvider : EasyCachingAbstractProvider /// /// The cache. /// - private readonly SqliteConnection _cache; + private SqliteConnection _cache => _dbProvider.GetConnection(); /// /// The cache stats. @@ -54,7 +54,6 @@ public DefaultSQLiteCachingProvider( this._dbProvider = dbProviders.Single(x => x.DBProviderName.Equals(name)); this._options = options; this._logger = loggerFactory?.CreateLogger(); - this._cache = _dbProvider.GetConnection(); this._cacheStats = new CacheStats(); this._name = name; From ccb068ccbbf5f9e588b63e352eff7c5b5724b4e0 Mon Sep 17 00:00:00 2001 From: haiduong87 Date: Thu, 26 Nov 2020 00:24:26 +0700 Subject: [PATCH 02/11] Improve issue #260 - Removing static variables - Test ok --- .../Configurations/SQLiteDatabaseProvider.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs b/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs index b3d19e24..e77283e0 100644 --- a/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs +++ b/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs @@ -1,4 +1,6 @@ -namespace EasyCaching.SQLite +using System; + +namespace EasyCaching.SQLite { using EasyCaching.Core; using Microsoft.Data.Sqlite; @@ -13,9 +15,19 @@ public class SQLiteDatabaseProvider : ISQLiteDatabaseProvider { /// - /// The options. + /// Connections pool + /// + private readonly ConcurrentDictionary _conns; + + /// + /// The options. /// private readonly SQLiteDBOptions _options; + + /// + /// The builder + /// + private readonly SqliteConnectionStringBuilder _builder; public SQLiteDatabaseProvider(string name , SQLiteOptions options) { @@ -31,13 +43,6 @@ public SQLiteDatabaseProvider(string name , SQLiteOptions options) _conns = new ConcurrentDictionary(); } - private static ConcurrentDictionary _conns; - - /// - /// The builder - /// - private static SqliteConnectionStringBuilder _builder; - private readonly string _name = EasyCachingConstValue.DefaultSQLiteName; public string DBProviderName => _name; @@ -53,7 +58,8 @@ public SqliteConnection GetConnection() Task.Run(async () => { - await Task.Delay(5000).ConfigureAwait(false); + //keep the connection for 30 minutes + await Task.Delay(TimeSpan.FromMinutes(30)).ConfigureAwait(false); _conns.TryRemove(threadId, out var removingConn); if (removingConn?.State == ConnectionState.Closed) { From 83880763ee57828b767c7bae4eeb9e8e12de22cb Mon Sep 17 00:00:00 2001 From: haiduong87 Date: Fri, 27 Nov 2020 00:11:00 +0700 Subject: [PATCH 03/11] Follow coding style --- .../Configurations/SQLiteDatabaseProvider.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs b/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs index e77283e0..fb662ef4 100644 --- a/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs +++ b/src/EasyCaching.SQLite/Configurations/SQLiteDatabaseProvider.cs @@ -1,10 +1,9 @@ -using System; - -namespace EasyCaching.SQLite +namespace EasyCaching.SQLite { using EasyCaching.Core; using Microsoft.Data.Sqlite; using System.Collections.Concurrent; + using System; using System.Data; using System.Threading; using System.Threading.Tasks; From 88fcefb41f5ead1f3e595eece519a7c757a48db6 Mon Sep 17 00:00:00 2001 From: Catcher Wong Date: Fri, 27 Nov 2020 08:11:51 +0800 Subject: [PATCH 04/11] SQLite 1.1.1 --- build/version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index 63cef48f..dbace977 100644 --- a/build/version.props +++ b/build/version.props @@ -3,7 +3,7 @@ 1.1.0 1.1.0 1.1.0 - 1.1.0 + 1.1.1 1.1.0 1.1.0 1.1.0 From ad1aaf79c0f469e1aa5b51c80bbd5d2e19712588 Mon Sep 17 00:00:00 2001 From: tracky Date: Mon, 14 Dec 2020 08:13:17 +0800 Subject: [PATCH 05/11] fix: Can't read CacheNulls option form config --- .../Configurations/EasyCachingOptionsExtensions.cs | 1 + .../Configurations/EasyCachingOptionsExtensions.cs | 1 + .../Configurations/EasyCachingOptionsExtensions.cs | 1 + .../Configurations/EasyCachingOptionsExtensions.cs | 1 + .../Configurations/EasyCachingOptionsExtensions.cs | 1 + .../Configurations/EasyCachingOptionsExtensions.cs | 1 + .../Configurations/EasyCachingOptionsExtensions.cs | 1 + 7 files changed, 7 insertions(+) diff --git a/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs index bd5bebfe..d3b9ad86 100644 --- a/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs @@ -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; } diff --git a/src/EasyCaching.Disk/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Disk/Configurations/EasyCachingOptionsExtensions.cs index 6ac281dc..5c3cbba4 100644 --- a/src/EasyCaching.Disk/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Disk/Configurations/EasyCachingOptionsExtensions.cs @@ -52,6 +52,7 @@ void configure(DiskOptions x) x.LockMs = diskOptions.LockMs; x.SleepMs = diskOptions.SleepMs; x.SerializerName = diskOptions.SerializerName; + x.CacheNulls = diskOptions.CacheNulls; x.DBConfig = diskOptions.DBConfig; } return options.UseDisk(configure, name); diff --git a/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs index 8608faed..0b190ce1 100644 --- a/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs @@ -80,6 +80,7 @@ void configure(InMemoryOptions x) x.LockMs = memoryOptions.LockMs; x.SleepMs = memoryOptions.SleepMs; x.SerializerName = memoryOptions.SerializerName; + x.CacheNulls = memoryOptions.CacheNulls; x.DBConfig = memoryOptions.DBConfig; } return options.UseInMemory(configure,name); diff --git a/src/EasyCaching.LiteDB/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.LiteDB/Configurations/EasyCachingOptionsExtensions.cs index 3af88846..efec1b92 100644 --- a/src/EasyCaching.LiteDB/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.LiteDB/Configurations/EasyCachingOptionsExtensions.cs @@ -54,6 +54,7 @@ void configure(LiteDBOptions x) x.LockMs = LiteDBOptions.LockMs; x.SleepMs = LiteDBOptions.SleepMs; x.SerializerName = LiteDBOptions.SerializerName; + x.CacheNulls = LiteDBOptions.CacheNulls; x.DBConfig = LiteDBOptions.DBConfig; } diff --git a/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs index 5662706c..e64d54d8 100644 --- a/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs @@ -54,6 +54,7 @@ void configure(MemcachedOptions x) x.LockMs = mOptions.LockMs; x.SleepMs = mOptions.SleepMs; x.SerializerName = mOptions.SerializerName; + x.CacheNulls = mOptions.CacheNulls; x.DBConfig = mOptions.DBConfig; } diff --git a/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs index 32599466..ccd3b192 100644 --- a/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs @@ -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; } diff --git a/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs index 71a259db..9f04cd65 100644 --- a/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs @@ -54,6 +54,7 @@ void configure(SQLiteOptions x) x.LockMs = sqliteOptions.LockMs; x.SleepMs = sqliteOptions.SleepMs; x.SerializerName = sqliteOptions.SerializerName; + x.CacheNulls = sqliteOptions.CacheNulls; x.DBConfig = sqliteOptions.DBConfig; } From 682e7b3c2298d0515a211c2cd2478e2f7d684339 Mon Sep 17 00:00:00 2001 From: Catcher Wong Date: Mon, 14 Dec 2020 08:30:32 +0800 Subject: [PATCH 06/11] Update version.props --- build/version.props | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/build/version.props b/build/version.props index dbace977..1fd6918b 100644 --- a/build/version.props +++ b/build/version.props @@ -1,24 +1,24 @@ - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.1 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 - 1.1.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 + 1.2.0 From 8bb7d9aba05b607ea1a7c8949a537bb272bab857 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Wed, 16 Dec 2020 11:09:23 +0800 Subject: [PATCH 07/11] try to improve (#270) --- Build.csproj | 2 +- .../DefaultCSRedisBus.cs | 1 + .../DefaultRabbitMQBus.cs | 4 ++- .../EasyCachingOptionsExtensions.cs | 8 +++-- .../IRedisSubscriberProvider.cs | 5 +++ .../Configurations/RedisBusOptions.cs | 5 +++ .../RedisBusOptionsExtension.cs | 33 ++++++++++++++++--- .../Configurations/RedisSubscriberProvider.cs | 13 +++++--- bus/EasyCaching.Bus.Redis/DefaultRedisBus.cs | 27 +++++++++++---- .../EasyCaching.Demo.Providers.csproj | 2 ++ sample/EasyCaching.Demo.Providers/Startup.cs | 16 +++++++++ src/EasyCaching.Core/Bus/IEasyCachingBus.cs | 5 +++ .../Bus/NullEasyCachingBus.cs | 2 ++ .../EasyCachingAbstractBus.cs | 4 +++ .../EasyCachingOptionsExtensions.cs | 2 +- .../CachingTests/BaseCachingProviderTest.cs | 4 +-- test/EasyCaching.UnitTests/Fake/FakeBus.cs | 2 ++ 17 files changed, 113 insertions(+), 22 deletions(-) diff --git a/Build.csproj b/Build.csproj index a15da8c5..29c45fee 100644 --- a/Build.csproj +++ b/Build.csproj @@ -1,7 +1,7 @@  - netcoreapp3.0 + netcoreapp3.1 false diff --git a/bus/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs b/bus/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs index a0a0910a..f5c05f35 100644 --- a/bus/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs +++ b/bus/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs @@ -22,6 +22,7 @@ public class DefaultCSRedisBus : EasyCachingAbstractBus /// Clients. public DefaultCSRedisBus(IEnumerable clients) { + this.BusName = "easycachingbus"; this._client = clients.FirstOrDefault(x => x.Name.Equals("easycachingbus")); } diff --git a/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs b/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs index 6599aa1a..cc8eec84 100644 --- a/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs +++ b/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs @@ -70,8 +70,10 @@ IPooledObjectPolicy _objectPolicy _subConnection = factory.CreateConnection(); _pubChannelPool = new DefaultObjectPool(_objectPolicy); - + _busId = Guid.NewGuid().ToString("N"); + + BusName = "easycachingbus"; } /// diff --git a/bus/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs b/bus/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs index 7e48c854..46f35f99 100644 --- a/bus/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs +++ b/bus/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs @@ -16,14 +16,16 @@ public static class EasyCachingOptionsExtensions /// /// Options. /// Configure bus settings. + /// name. public static EasyCachingOptions WithRedisBus( this EasyCachingOptions options , Action configure + , string name = EasyCachingConstValue.DefaultRedisName ) { ArgumentCheck.NotNull(configure, nameof(configure)); - options.RegisterExtension(new RedisBusOptionsExtension(configure)); + options.RegisterExtension(new RedisBusOptionsExtension(name, configure)); return options; } @@ -32,10 +34,12 @@ this EasyCachingOptions options /// /// Options. /// The configuration. + /// The name. /// The section name in the configuration file. public static EasyCachingOptions WithRedisBus( this EasyCachingOptions options , IConfiguration configuration + , string name = EasyCachingConstValue.DefaultRedisName , string sectionName = EasyCachingConstValue.RedisBusSection ) { @@ -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; } } diff --git a/bus/EasyCaching.Bus.Redis/Configurations/IRedisSubscriberProvider.cs b/bus/EasyCaching.Bus.Redis/Configurations/IRedisSubscriberProvider.cs index f9a2ca5e..ec0a505e 100644 --- a/bus/EasyCaching.Bus.Redis/Configurations/IRedisSubscriberProvider.cs +++ b/bus/EasyCaching.Bus.Redis/Configurations/IRedisSubscriberProvider.cs @@ -12,5 +12,10 @@ public interface IRedisSubscriberProvider /// /// The subscriber. ISubscriber GetSubscriber(); + + /// + /// Gets the name of subscriber. + /// + string SubscriberName { get; } } } diff --git a/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs b/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs index 46bcdb6f..679262a5 100644 --- a/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs +++ b/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs @@ -12,5 +12,10 @@ public class RedisBusOptions : BaseRedisOptions /// /// The database. public int Database { get; set; } = 0; + + /// + /// Gets or sets the serializer name that should be use in this bus. + /// + public string SerializerName { get; set; } } } diff --git a/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs b/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs index e1cd60f2..fe06b869 100644 --- a/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs +++ b/bus/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs @@ -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; /// /// Redis bus options extension. /// internal sealed class RedisBusOptionsExtension : IEasyCachingOptionsExtension { + /// + /// The name. + /// + private readonly string _name; + /// /// The configure. /// @@ -20,9 +27,11 @@ internal sealed class RedisBusOptionsExtension : IEasyCachingOptionsExtension /// /// Initializes a new instance of the class. /// + /// Name. /// Configure. - public RedisBusOptionsExtension(Action configure) - { + public RedisBusOptionsExtension(string name, Action configure) + { + this._name = name; this.configure = configure; } @@ -33,11 +42,25 @@ public RedisBusOptionsExtension(Action configure) public void AddServices(IServiceCollection services) { services.AddOptions(); - services.Configure(configure); + services.Configure(_name, configure); services.TryAddSingleton(); - services.TryAddSingleton(); - services.AddSingleton(); + services.AddSingleton(x => + { + var optionsMon = x.GetRequiredService>(); + var options = optionsMon.Get(_name); + return new RedisSubscriberProvider(_name, options); + }); + + services.AddSingleton(x => + { + var subProviders = x.GetServices(); + var serializers = x.GetServices(); + var optionsMon = x.GetRequiredService>(); + var options = optionsMon.Get(_name); + var factory = x.GetService(); + return new DefaultRedisBus(_name, subProviders, options, serializers); + }); } } } diff --git a/bus/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs b/bus/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs index 76d74b43..160885a6 100644 --- a/bus/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs +++ b/bus/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs @@ -1,6 +1,5 @@ namespace EasyCaching.Bus.Redis { - using Microsoft.Extensions.Options; using StackExchange.Redis; using System; @@ -9,6 +8,8 @@ /// internal class RedisSubscriberProvider : IRedisSubscriberProvider { + private readonly string _name; + /// /// The options. /// @@ -22,19 +23,23 @@ internal class RedisSubscriberProvider : IRedisSubscriberProvider /// /// Initializes a new instance of the class. /// + /// name. /// Options. - public RedisSubscriberProvider(IOptions options) + public RedisSubscriberProvider(string name, RedisBusOptions options) { - _options = options.Value; + _name = name; + _options = options; _connectionMultiplexer = new Lazy(CreateConnectionMultiplexer); } + public string SubscriberName => _name; + /// /// Gets the database connection. /// public ISubscriber GetSubscriber() { - return _connectionMultiplexer.Value.GetSubscriber(); + return _connectionMultiplexer.Value.GetSubscriber(); } /// diff --git a/bus/EasyCaching.Bus.Redis/DefaultRedisBus.cs b/bus/EasyCaching.Bus.Redis/DefaultRedisBus.cs index b9243c7f..f703aef5 100644 --- a/bus/EasyCaching.Bus.Redis/DefaultRedisBus.cs +++ b/bus/EasyCaching.Bus.Redis/DefaultRedisBus.cs @@ -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; @@ -28,17 +30,30 @@ public class DefaultRedisBus : EasyCachingAbstractBus /// private readonly IEasyCachingSerializer _serializer; + /// + /// The name. + /// + private readonly string _name; + /// /// Initializes a new instance of the class. /// - /// Subscriber provider. - /// Serializer. + /// Name. + /// Subscriber provider. + /// bus Options. + /// Serializers. public DefaultRedisBus( - IRedisSubscriberProvider subscriberProvider, - IEasyCachingSerializer serializer) + string name + , IEnumerable subscriberProviders + , RedisBusOptions busOptions + , IEnumerable 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(); } diff --git a/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj b/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj index 9e2993e6..20bf68ca 100644 --- a/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj +++ b/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj @@ -12,6 +12,8 @@ + + diff --git a/sample/EasyCaching.Demo.Providers/Startup.cs b/sample/EasyCaching.Demo.Providers/Startup.cs index db4aab2f..6c5a30a8 100644 --- a/sample/EasyCaching.Demo.Providers/Startup.cs +++ b/sample/EasyCaching.Demo.Providers/Startup.cs @@ -60,6 +60,22 @@ public void ConfigureServices(IServiceCollection services) option.UseMemcached(Configuration); + option.UseHybrid(x => + { + + }, "name"); + + option.WithRedisBus(x => + { + x.SerializerName = "msgpack"; + }, "bus"); + + option.WithCSRedisBus(x => + { + + }); + + option.WithMessagePack("msgpack"); }); } diff --git a/src/EasyCaching.Core/Bus/IEasyCachingBus.cs b/src/EasyCaching.Core/Bus/IEasyCachingBus.cs index 743b13a9..f6a7e442 100644 --- a/src/EasyCaching.Core/Bus/IEasyCachingBus.cs +++ b/src/EasyCaching.Core/Bus/IEasyCachingBus.cs @@ -5,5 +5,10 @@ /// public interface IEasyCachingBus : IEasyCachingPublisher , IEasyCachingSubscriber { + /// + /// Gets the name. + /// + /// The name. + string Name { get; } } } diff --git a/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs b/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs index 199744e7..a64a16e8 100644 --- a/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs +++ b/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs @@ -14,6 +14,8 @@ public class NullEasyCachingBus : IEasyCachingBus /// public static readonly NullEasyCachingBus Instance = new NullEasyCachingBus(); + public string Name => nameof(NullEasyCachingBus); + /// /// Releases all resource used by the object. /// diff --git a/src/EasyCaching.Core/EasyCachingAbstractBus.cs b/src/EasyCaching.Core/EasyCachingAbstractBus.cs index ab4627d8..5031bd27 100644 --- a/src/EasyCaching.Core/EasyCachingAbstractBus.cs +++ b/src/EasyCaching.Core/EasyCachingAbstractBus.cs @@ -18,6 +18,10 @@ public abstract class EasyCachingAbstractBus : IEasyCachingBus protected Action _handler; + protected string BusName { get; set; } + + public string Name => this.BusName; + public void Publish(string topic, EasyCachingMessage message) { var operationId = s_diagnosticListener.WritePublishMessageBefore(new BeforePublishMessageRequestEventData(topic, message)); diff --git a/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs index ccd3b192..e30d879f 100644 --- a/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs @@ -50,7 +50,7 @@ this EasyCachingOptions options void configure(RedisOptions x) { x.EnableLogging = redisOptions.EnableLogging; - x.MaxRdSecond = redisOptions.MaxRdSecond; + x.MaxRdSecond = redisOptions.MaxRdSecond; x.LockMs = redisOptions.LockMs; x.SleepMs = redisOptions.SleepMs; x.SerializerName = redisOptions.SerializerName; diff --git a/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs index 5c4762f0..39910bb6 100644 --- a/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/BaseCachingProviderTest.cs @@ -959,7 +959,7 @@ protected virtual void GetAll_Should_Succeed_When_One_Of_Values_Is_Null_And_Null Assert.Contains($"{_nameSpace}getallwithnull:key:1",res.Select(x => x.Key)); Assert.Contains($"{_nameSpace}getallwithnull:key:2", res.Select(x => x.Key)); Assert.Equal("value1", res.Where(x => x.Key == $"{_nameSpace}getallwithnull:key:1").Select(x => x.Value).FirstOrDefault().Value); - Assert.Equal(null, res.Where(x => x.Key == $"{_nameSpace}getallwithnull:key:2").Select(x => x.Value).FirstOrDefault().Value); + Assert.Null(res.Where(x => x.Key == $"{_nameSpace}getallwithnull:key:2").Select(x => x.Value).FirstOrDefault().Value); } [Fact] @@ -999,7 +999,7 @@ protected virtual async Task GetAllAsync_Should_Succeed_When_One_Of_Values_Is_Nu Assert.Contains($"{_nameSpace}getallasyncwithnull:key:1", res.Select(x => x.Key)); Assert.Contains($"{_nameSpace}getallasyncwithnull:key:2", res.Select(x => x.Key)); Assert.Equal("value1", res.Where(x => x.Key == $"{_nameSpace}getallasyncwithnull:key:1").Select(x => x.Value).FirstOrDefault().Value); - Assert.Equal(null, res.Where(x => x.Key == $"{_nameSpace}getallasyncwithnull:key:2").Select(x => x.Value).FirstOrDefault().Value); + Assert.Null(res.Where(x => x.Key == $"{_nameSpace}getallasyncwithnull:key:2").Select(x => x.Value).FirstOrDefault().Value); } [Fact] diff --git a/test/EasyCaching.UnitTests/Fake/FakeBus.cs b/test/EasyCaching.UnitTests/Fake/FakeBus.cs index 5c4cbb79..db96bc11 100644 --- a/test/EasyCaching.UnitTests/Fake/FakeBus.cs +++ b/test/EasyCaching.UnitTests/Fake/FakeBus.cs @@ -7,6 +7,8 @@ public class FakeBus : IEasyCachingBus { + public string Name => nameof(FakeBus); + public void Publish(string topic, EasyCachingMessage message) { From 24ffb34cc3a2c8201adb1c976e942a3c7e2c1ae4 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Wed, 16 Dec 2020 12:04:39 +0800 Subject: [PATCH 08/11] myget preview --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 20385651..5d256c6a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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/v3/index.json done \ No newline at end of file From 4b0aed9b536c2f342587f5b29a26c1d511a2eefb Mon Sep 17 00:00:00 2001 From: catcherwong Date: Wed, 16 Dec 2020 13:32:20 +0800 Subject: [PATCH 09/11] modify the myget url --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d256c6a..d0c2316f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,5 +43,5 @@ jobs: run: | for file in nugetpkgs/*.nupkg do - dotnet nuget push $file -k ${{ secrets.MYGET_API_KEY }} --skip-duplicate -s https://www.myget.org/F/ncc/api/v3/index.json + dotnet nuget push $file -k ${{ secrets.MYGET_API_KEY }} --skip-duplicate -s https://www.myget.org/F/ncc/api/v2/package done \ No newline at end of file From e473dabd8a7c8af9159e44db86bb230efc964435 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Wed, 16 Dec 2020 13:34:35 +0800 Subject: [PATCH 10/11] update sample --- sample/EasyCaching.Demo.Providers/Startup.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/sample/EasyCaching.Demo.Providers/Startup.cs b/sample/EasyCaching.Demo.Providers/Startup.cs index 6c5a30a8..288b1a5c 100644 --- a/sample/EasyCaching.Demo.Providers/Startup.cs +++ b/sample/EasyCaching.Demo.Providers/Startup.cs @@ -59,23 +59,6 @@ public void ConfigureServices(IServiceCollection services) }); option.UseMemcached(Configuration); - - option.UseHybrid(x => - { - - }, "name"); - - option.WithRedisBus(x => - { - x.SerializerName = "msgpack"; - }, "bus"); - - option.WithCSRedisBus(x => - { - - }); - - option.WithMessagePack("msgpack"); }); } From 09fc607e664ccd3443304e2d74323adc83a495f1 Mon Sep 17 00:00:00 2001 From: catcherwong Date: Thu, 24 Dec 2020 08:24:51 +0800 Subject: [PATCH 11/11] fixed UTF-8 BOM of Newtonsoft.Json (#272) --- .../DefaultJsonSerializer.cs | 11 ++++++++--- .../DefaultJsonSerializer.cs | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/serialization/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs b/serialization/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs index 8df4281b..87c80726 100644 --- a/serialization/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs +++ b/serialization/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs @@ -17,6 +17,11 @@ public class DefaultJsonSerializer : IEasyCachingSerializer /// private readonly JsonSerializer jsonSerializer; + /// + /// default utf-8 encoding + /// + private static readonly UTF8Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); + /// /// The name. /// @@ -48,7 +53,7 @@ public DefaultJsonSerializer(string name, JsonSerializerSettings serializerSetti public T Deserialize(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(jtr); @@ -64,7 +69,7 @@ public T Deserialize(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); @@ -81,7 +86,7 @@ public byte[] Serialize(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); diff --git a/serialization/EasyCaching.Serialization.SystemTextJson/DefaultJsonSerializer.cs b/serialization/EasyCaching.Serialization.SystemTextJson/DefaultJsonSerializer.cs index dc2a6b44..5a314471 100644 --- a/serialization/EasyCaching.Serialization.SystemTextJson/DefaultJsonSerializer.cs +++ b/serialization/EasyCaching.Serialization.SystemTextJson/DefaultJsonSerializer.cs @@ -80,8 +80,9 @@ public object DeserializeObject(ArraySegment value) throw new InvalidDataException("JsonTranscoder only supports [\"TypeName\", object]"); } } + /// - //; Serialize the specified value. + /// Serialize the specified value. /// /// The serialize. /// Value.