diff --git a/EasyCaching.sln b/EasyCaching.sln
index 415a25e5..e8f9f0fc 100644
--- a/EasyCaching.sln
+++ b/EasyCaching.sln
@@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.PerformanceTest
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.CSRedis", "src\EasyCaching.CSRedis\EasyCaching.CSRedis.csproj", "{6584761E-E51C-408F-BE51-CA0F6269589B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Bus.CSRedis", "src\EasyCaching.Bus.CSRedis\EasyCaching.Bus.CSRedis.csproj", "{861E5373-BEF6-4AA2-92C7-8F4941A079E7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -133,6 +135,10 @@ Global
{6584761E-E51C-408F-BE51-CA0F6269589B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6584761E-E51C-408F-BE51-CA0F6269589B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6584761E-E51C-408F-BE51-CA0F6269589B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CE61FAA2-0233-451C-991D-4222ED61C84B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
@@ -155,5 +161,6 @@ Global
{2A8D7103-DF64-47B6-A406-8F8559AF7E7F} = {EBB55F65-7D07-4281-8D5E-7B0CA88E1AD0}
{6EBE36A2-F128-4C63-B90A-B700D8C2F2E8} = {EBB55F65-7D07-4281-8D5E-7B0CA88E1AD0}
{6584761E-E51C-408F-BE51-CA0F6269589B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
+ {861E5373-BEF6-4AA2-92C7-8F4941A079E7} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
EndGlobalSection
EndGlobal
diff --git a/LICENSE b/LICENSE
index 0608e35d..9b54c526 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2017-2018 CatcherWong
+Copyright (c) .NET Core Community and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/build/releasenotes.props b/build/releasenotes.props
index c795beb3..d8453fea 100644
--- a/build/releasenotes.props
+++ b/build/releasenotes.props
@@ -1,50 +1,53 @@
-
- 1. EasyCaching Bus
- 2. HybridCaching
+
+ 1. HybridCaching add RemoveByPrefix/RemoveByPrefixAsync
+ 2. Add Bus Section Const value.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
+ 2. Update Default name of provider.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Refactor.
+ 1. HybridCaching add RemoveByPrefix/RemoveByPrefixAsync
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Adjust reference namespace.
+ 1. Update EasyCaching.Core.
- 1. Init.
+ 1. Modify the default section name.
+ 2. Update EasyCaching.Core.
- 1. Init.
+ 1. Fixed Options Bug.
+ 2. Fixed Queue Bind Bug.
diff --git a/build/version.props b/build/version.props
index 83d48727..18115f2f 100644
--- a/build/version.props
+++ b/build/version.props
@@ -1,19 +1,20 @@
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0
- 0.5.0-alpha
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1
+ 0.5.1.1
diff --git a/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj b/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj
index dd3b067c..34371c8c 100644
--- a/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj
+++ b/sample/EasyCaching.Demo.Providers/EasyCaching.Demo.Providers.csproj
@@ -16,6 +16,7 @@
+
diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs
new file mode 100644
index 00000000..bfb1c05a
--- /dev/null
+++ b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisBusOptions.cs
@@ -0,0 +1,23 @@
+namespace EasyCaching.Bus.CSRedis
+{
+ using System;
+ using System.Collections.Generic;
+
+ ///
+ /// Redis bus options.
+ ///
+ public class CSRedisBusOptions
+ {
+ ///
+ /// Gets or sets the node rule.
+ ///
+ /// The node rule.
+ public Func NodeRule { get; set; } = null;
+
+ ///
+ /// Gets or sets the connection strings.
+ ///
+ /// The connection strings.
+ public List ConnectionStrings { get; set; }
+ }
+}
diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs
new file mode 100755
index 00000000..feedfd31
--- /dev/null
+++ b/src/EasyCaching.Bus.CSRedis/Configurations/CSRedisOptionsExtension.cs
@@ -0,0 +1,81 @@
+namespace EasyCaching.Bus.CSRedis
+{
+ using System;
+ using EasyCaching.Core.Bus;
+ using EasyCaching.Core.Configurations;
+ using EasyCaching.Core.Serialization;
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.Extensions.DependencyInjection;
+ using Microsoft.Extensions.DependencyInjection.Extensions;
+ using Microsoft.Extensions.Options;
+
+ ///
+ /// Redis options extension.
+ ///
+ internal sealed class CSRedisOptionsExtension : IEasyCachingOptionsExtension
+ {
+ ///
+ /// The name.
+ ///
+ private const string _name = "easycachingbus";
+
+ ///
+ /// The configure.
+ ///
+ private readonly Action _configure;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Name.
+ /// Configure.
+ public CSRedisOptionsExtension(Action configure)
+ {
+ this._configure = configure;
+ }
+
+ ///
+ /// Adds the services.
+ ///
+ /// Services.
+ public void AddServices(IServiceCollection services)
+ {
+ services.AddOptions();
+
+ services.TryAddSingleton();
+
+ services.Configure(_name, _configure);
+
+ services.AddSingleton(x =>
+ {
+ var optionsMon = x.GetRequiredService>();
+ var options = optionsMon.Get(_name);
+
+ var conns = options.ConnectionStrings;
+ var rule = options.NodeRule;
+
+ if (conns.Count == 1)
+ {
+ var redisClient = new EasyCachingCSRedisClient(_name, conns[0]);
+ return redisClient;
+ }
+ else
+ {
+ var redisClient = new EasyCachingCSRedisClient(_name, rule, conns.ToArray());
+ return redisClient;
+ }
+ });
+
+ services.AddSingleton();
+ }
+
+ ///
+ /// Withs the services.
+ ///
+ /// Services.
+ public void WithServices(IApplicationBuilder services)
+ {
+ // Method intentionally left empty.
+ }
+ }
+}
diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs
new file mode 100755
index 00000000..bb577f62
--- /dev/null
+++ b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingCSRedisClient.cs
@@ -0,0 +1,24 @@
+namespace EasyCaching.Bus.CSRedis
+{
+ using System;
+ using global::CSRedis;
+
+ public class EasyCachingCSRedisClient : CSRedisClient
+ {
+ private readonly string _name;
+
+ public string Name { get { return this._name; } }
+
+ public EasyCachingCSRedisClient(string name, string connectionString)
+ : base(connectionString)
+ {
+ this._name = name;
+ }
+
+ public EasyCachingCSRedisClient(string name, Func NodeRule, params string[] connectionStrings)
+ : base(NodeRule, connectionStrings)
+ {
+ this._name = name;
+ }
+ }
+}
diff --git a/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs
new file mode 100644
index 00000000..1c6253dc
--- /dev/null
+++ b/src/EasyCaching.Bus.CSRedis/Configurations/EasyCachingOptionsExtensions.cs
@@ -0,0 +1,52 @@
+namespace EasyCaching.Bus.CSRedis
+{
+ using System;
+ using EasyCaching.Core;
+ using EasyCaching.Core.Configurations;
+ using Microsoft.Extensions.Configuration;
+
+ ///
+ /// EasyCaching options extensions.
+ ///
+ public static class EasyCachingOptionsExtensions
+ {
+ ///
+ /// Withs the redis bus.
+ ///
+ /// The redis bus.
+ /// Options.
+ /// Configure.
+ public static EasyCachingOptions WithCSRedisBus(this EasyCachingOptions options, Action configure)
+ {
+ if (configure == null)
+ {
+ throw new ArgumentNullException(nameof(configure));
+ }
+
+ options.RegisterExtension(new CSRedisOptionsExtension(configure));
+ return options;
+ }
+
+ ///
+ /// Withs the redis bus.
+ ///
+ /// The redis bus.
+ /// Options.
+ /// Configuration.
+ /// Section name.
+ public static EasyCachingOptions WithCSRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RedisBusSection)
+ {
+ var dbConfig = configuration.GetSection(sectionName);
+ var redisOptions = new CSRedisBusOptions();
+ dbConfig.Bind(redisOptions);
+
+ void configure(CSRedisBusOptions x)
+ {
+ x.ConnectionStrings = redisOptions.ConnectionStrings;
+ }
+
+ options.RegisterExtension(new CSRedisOptionsExtension(configure));
+ return options;
+ }
+ }
+}
diff --git a/src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs b/src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs
new file mode 100644
index 00000000..8c7199ec
--- /dev/null
+++ b/src/EasyCaching.Bus.CSRedis/DefaultCSRedisBus.cs
@@ -0,0 +1,83 @@
+namespace EasyCaching.Bus.CSRedis
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using EasyCaching.Core.Bus;
+ using Newtonsoft.Json;
+
+ public class DefaultCSRedisBus : IEasyCachingBus
+ {
+ ///
+ /// The cache.
+ ///
+ private readonly EasyCachingCSRedisClient _client;
+
+ ///
+ /// The handler.
+ ///
+ private Action _handler;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Clients.
+ public DefaultCSRedisBus(IEnumerable clients)
+ {
+ this._client = clients.FirstOrDefault(x => x.Name.Equals("easycachingbus"));
+ }
+
+ ///
+ /// Publish the specified topic and message.
+ ///
+ /// Topic.
+ /// Message.
+ public void Publish(string topic, EasyCachingMessage message)
+ {
+ var msg = JsonConvert.SerializeObject(message);
+
+ _client.Publish(topic, msg);
+ }
+
+ ///
+ /// Publishs the async.
+ ///
+ /// The async.
+ /// Topic.
+ /// Message.
+ /// Cancellation token.
+ public async Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ var msg = JsonConvert.SerializeObject(message);
+
+ await _client.PublishAsync(topic, msg);
+ }
+
+ ///
+ /// Subscribe the specified topic and action.
+ ///
+ /// Topic.
+ /// Action.
+ public void Subscribe(string topic, Action action)
+ {
+ _handler = action;
+
+ _client.Subscribe(
+ (topic, msg => OnMessage(msg.Body))
+ );
+ }
+
+ ///
+ /// Ons the message.
+ ///
+ /// Body.
+ private void OnMessage(string body)
+ {
+ var message = JsonConvert.DeserializeObject(body);
+
+ _handler?.Invoke(message);
+ }
+ }
+}
diff --git a/src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj b/src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj
new file mode 100644
index 00000000..565c7adc
--- /dev/null
+++ b/src/EasyCaching.Bus.CSRedis/EasyCaching.Bus.CSRedis.csproj
@@ -0,0 +1,33 @@
+
+
+
+
+ netstandard2.0
+ Catcher Wong
+ Catcher Wong
+ $(EasyCachingRedisBusPackageVersion)
+
+ A simple caching bus(message bus) based on CSRedis.
+
+ Bus,Hybrid,Redis,Caching,Cache
+ https://github.com/dotnetcore/EasyCaching
+ https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE
+ https://github.com/dotnetcore/EasyCaching
+ https://github.com/dotnetcore/EasyCaching
+ https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png
+
+ $(EasyCachingRedisBusPackageNotes)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs
index a58a6829..c44768da 100644
--- a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs
+++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs
@@ -1,6 +1,7 @@
namespace EasyCaching.Bus.RabbitMQ
{
using System;
+ using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using Microsoft.Extensions.Configuration;
@@ -33,7 +34,7 @@ public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options
/// Options.
/// Configuration.
/// Section name.
- public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "rabbitmqbus")
+ public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RabbitMQBusSection)
{
var dbConfig = configuration.GetSection(sectionName);
var busOptions = new RabbitMQBusOptions();
@@ -46,7 +47,7 @@ void configure(RabbitMQBusOptions x)
x.Port = busOptions.Port;
x.QueueMessageExpires = busOptions.QueueMessageExpires;
x.RequestedConnectionTimeout = busOptions.RequestedConnectionTimeout;
- x.RouteKey = busOptions.RouteKey;
+ //x.RouteKey = busOptions.RouteKey;
x.SocketReadTimeout = busOptions.SocketReadTimeout;
x.SocketWriteTimeout = busOptions.SocketWriteTimeout;
x.TopicExchangeName = busOptions.TopicExchangeName;
diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs
index bf0da3d2..5b2bb79b 100644
--- a/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs
+++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs
@@ -11,7 +11,7 @@ public class RabbitMQBusOptions : BaseRabbitMQOptions
/// Gets or sets the route key.
///
/// The route key.
- public string RouteKey { get; set; } = "rmq.queue.undurable.easycaching.subscriber.*";
+ //public string RouteKey { get; set; } = "rmq.queue.undurable.easycaching.subscriber.*";
///
/// Gets or sets the name of the queue.
diff --git a/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs b/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs
index a8c178ae..dd517018 100644
--- a/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs
+++ b/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs
@@ -8,6 +8,7 @@
using global::RabbitMQ.Client;
using global::RabbitMQ.Client.Events;
using Microsoft.Extensions.ObjectPool;
+ using Microsoft.Extensions.Options;
///
/// Default RabbitMQ Bus.
@@ -52,10 +53,10 @@ public class DefaultRabbitMQBus : IEasyCachingBus
/// Serializer.
public DefaultRabbitMQBus(
IPooledObjectPolicy _objectPolicy
- ,RabbitMQBusOptions rabbitMQOptions
- ,IEasyCachingSerializer serializer)
+ , IOptions rabbitMQOptions
+ , IEasyCachingSerializer serializer)
{
- this._options = rabbitMQOptions;
+ this._options = rabbitMQOptions.Value;
this._serializer = serializer;
var factory = new ConnectionFactory
@@ -132,7 +133,7 @@ public void Publish(string topic, EasyCachingMessage message)
}
return Task.CompletedTask;
}
-
+
///
/// Subscribe the specified topic and action.
///
@@ -142,7 +143,7 @@ public void Subscribe(string topic, Action action)
{
_handler = action;
var queueName = string.Empty;
- if(string.IsNullOrWhiteSpace(_options.QueueName))
+ if (string.IsNullOrWhiteSpace(_options.QueueName))
{
queueName = $"rmq.queue.undurable.easycaching.subscriber.{_busId}";
}
@@ -151,13 +152,13 @@ public void Subscribe(string topic, Action action)
queueName = _options.QueueName;
}
- Task.Factory.StartNew(() =>
+ Task.Factory.StartNew(() =>
{
var model = _subConnection.CreateModel();
model.ExchangeDeclare(_options.TopicExchangeName, ExchangeType.Topic, true, false, null);
model.QueueDeclare(queueName, false, false, true, null);
// bind the queue with the exchange.
- model.QueueBind(_options.TopicExchangeName, queueName, _options.RouteKey);
+ model.QueueBind(queueName, _options.TopicExchangeName, topic);
var consumer = new EventingBasicConsumer(model);
consumer.Received += OnMessage;
consumer.Shutdown += OnConsumerShutdown;
diff --git a/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj b/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj
index 0871cb3b..bbf67258 100644
--- a/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj
+++ b/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj
@@ -1,5 +1,6 @@
-
+
+
netstandard2.0
Catcher Wong
@@ -13,7 +14,7 @@
https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE
https://github.com/dotnetcore/EasyCaching
https://github.com/dotnetcore/EasyCaching
- https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/easycaching-icon.png
+ https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png
$(EasyCachingRabbitBusPackageNotes)
diff --git a/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs
index 0c5192e5..c5e28540 100644
--- a/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs
+++ b/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs
@@ -1,6 +1,7 @@
namespace EasyCaching.Bus.Redis
{
using System;
+ using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using Microsoft.Extensions.Configuration;
@@ -33,7 +34,7 @@ public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, A
/// Options.
/// Configuration.
/// Section name.
- public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "redisbus")
+ public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = EasyCachingConstValue.RedisBusSection)
{
var dbConfig = configuration.GetSection(sectionName);
var redisOptions = new RedisBusOptions();
diff --git a/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj b/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj
index 5ef428bf..1d1dab6c 100644
--- a/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj
+++ b/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj
@@ -1,5 +1,6 @@
-
+
+
netstandard2.0
Catcher Wong
@@ -13,7 +14,7 @@
https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE
https://github.com/dotnetcore/EasyCaching
https://github.com/dotnetcore/EasyCaching
- https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/easycaching-icon.png
+ https://raw.githubusercontent.com/dotnetcore/EasyCaching/master/media/nuget-icon.png
$(EasyCachingRedisBusPackageNotes)
diff --git a/src/EasyCaching.Core/Bus/EasyCachingMessage.cs b/src/EasyCaching.Core/Bus/EasyCachingMessage.cs
index c8b86729..09bf6e1a 100644
--- a/src/EasyCaching.Core/Bus/EasyCachingMessage.cs
+++ b/src/EasyCaching.Core/Bus/EasyCachingMessage.cs
@@ -19,5 +19,11 @@ public class EasyCachingMessage
///
/// The cache keys.
public string[] CacheKeys { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether this is prefix.
+ ///
+ /// true if is prefix; otherwise, false.
+ public bool IsPrefix { get; set; }
}
}
diff --git a/src/EasyCaching.Core/IHybridCachingProvider.cs b/src/EasyCaching.Core/IHybridCachingProvider.cs
index 71ffc239..a82e4abd 100644
--- a/src/EasyCaching.Core/IHybridCachingProvider.cs
+++ b/src/EasyCaching.Core/IHybridCachingProvider.cs
@@ -141,5 +141,16 @@ public interface IHybridCachingProvider
/// The 1st type parameter.
Task> GetAsync(string cacheKey, Func> dataRetriever, TimeSpan expiration);
+ ///
+ /// Removes cached item by cachekey's prefix.
+ ///
+ /// Prefix of CacheKey.
+ void RemoveByPrefix(string prefix);
+
+ ///
+ /// Removes cached item by cachekey's prefix async.
+ ///
+ /// Prefix of CacheKey.
+ Task RemoveByPrefixAsync(string prefix);
}
}
diff --git a/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs b/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs
index 55ffb426..9d94e559 100644
--- a/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs
+++ b/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs
@@ -35,6 +35,16 @@ public class EasyCachingConstValue
///
public const string InMemorySection = "easycaching:inmemory";
+ ///
+ /// The redis bus section.
+ ///
+ public const string RedisBusSection = "easycaching:redisbus";
+
+ ///
+ /// The rabbitMQ Bus section.
+ ///
+ public const string RabbitMQBusSection = "easycaching:rabbitmqbus";
+
///
/// The default name of the in-memory.
///
diff --git a/src/EasyCaching.HybridCache/HybridCachingProvider.cs b/src/EasyCaching.HybridCache/HybridCachingProvider.cs
index 62ea2b7e..ce8f78f8 100644
--- a/src/EasyCaching.HybridCache/HybridCachingProvider.cs
+++ b/src/EasyCaching.HybridCache/HybridCachingProvider.cs
@@ -88,6 +88,21 @@ private void OnMessage(EasyCachingMessage message)
// each clients will recive the message, current client should ignore.
if (!string.IsNullOrWhiteSpace(message.Id) && message.Id.Equals(_cacheId, StringComparison.OrdinalIgnoreCase))
return;
+
+ //remove by prefix
+ if(message.IsPrefix)
+ {
+ var prefix = message.CacheKeys.First();
+
+ _localCache.RemoveByPrefix(prefix);
+
+ if (_options.EnableLogging)
+ {
+ _logger.LogTrace($"remove local cache that prefix is {prefix}");
+ }
+
+ return;
+ }
foreach (var item in message.CacheKeys)
{
@@ -429,5 +444,38 @@ public async Task> GetAsync(string cacheKey, Func> data
? result
: CacheValue.NoValue;
}
+
+ ///
+ /// Removes the by prefix.
+ ///
+ /// Prefix.
+ public void RemoveByPrefix(string prefix)
+ {
+ ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));
+
+ //distributed cache at first
+ _distributedCache.RemoveByPrefix(prefix);
+ _localCache.RemoveByPrefix(prefix);
+
+ //send message to bus
+ _bus.Publish(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { prefix } , IsPrefix = true });
+ }
+
+ ///
+ /// Removes the by prefix async.
+ ///
+ /// The by prefix async.
+ /// Prefix.
+ public async Task RemoveByPrefixAsync(string prefix)
+ {
+ ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));
+
+ await _localCache.RemoveByPrefixAsync(prefix);
+
+ await _distributedCache.RemoveByPrefixAsync(prefix);
+
+ //send message to bus in order to notify other clients.
+ await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { prefix }, IsPrefix = true });
+ }
}
}
diff --git a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs
index 45ffc180..87be581a 100644
--- a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs
+++ b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs
@@ -60,7 +60,7 @@ public DefaultSQLiteCachingProvider(
this._logger = loggerFactory?.CreateLogger();
this._cache = _dbProvider.GetConnection();
this._cacheStats = new CacheStats();
- this._name = EasyCachingConstValue.DefaultRedisName;
+ this._name = EasyCachingConstValue.DefaultSQLiteName;
}
public DefaultSQLiteCachingProvider(