diff --git a/build/releasenotes.props b/build/releasenotes.props index 97c4d902..c795beb3 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -1,44 +1,50 @@ - 1. Add IRedisCachingProvider. + 1. EasyCaching Bus + 2. HybridCaching - 1. Improve Get cached value. + 1. Adjust reference namespace. - 1. Add Impl of IRedisCachingProvider. + 1. Adjust reference namespace. - 1. Improve Configuration. + 1. Adjust reference namespace. - 1. Update Options. - 2. Improve Get cached value. + 1. Adjust reference namespace. - 1. Improve Configuration. + 1. Refactor. - 1. Fixed bug of IConvertible. + 1. Adjust reference namespace. - 1. Remove Dependency of IEasyCaching. + 1. Adjust reference namespace. - 1. Support .NET Core 2.1 + 1. Adjust reference namespace. - 1. Improve Configuration. + 1. Adjust reference namespace. - 1. Improve Configuration. + 1. Adjust reference namespace. - 1. Improve Configuration. + 1. Adjust reference namespace. - 1. Init. + 1. Adjust reference namespace. + + 1. Init. + + + 1. Init. + diff --git a/build/version.props b/build/version.props index 2b074824..83d48727 100644 --- a/build/version.props +++ b/build/version.props @@ -1,17 +1,19 @@ - 0.4.6 - 0.4.5.1 - 0.4.6 - 0.4.5 - 0.4.6 - 0.4.5 - 0.3.3 - 0.3.2 - 0.3.0 - 0.3.5 - 0.3.5 - 0.3.5 - 0.1.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 + 0.5.0-alpha diff --git a/media/hybrid_details.png b/media/hybrid_details.png new file mode 100644 index 00000000..78a6505b Binary files /dev/null and b/media/hybrid_details.png differ diff --git a/sample/EasyCaching.Demo.Interceptors/Services/IAspectCoreService.cs b/sample/EasyCaching.Demo.Interceptors/Services/IAspectCoreService.cs index d9d6cdbd..ec52ea66 100644 --- a/sample/EasyCaching.Demo.Interceptors/Services/IAspectCoreService.cs +++ b/sample/EasyCaching.Demo.Interceptors/Services/IAspectCoreService.cs @@ -1,8 +1,8 @@ namespace EasyCaching.Demo.Interceptors.Services { - using EasyCaching.Core.Internal; using System.Threading.Tasks; - + using EasyCaching.Core.Interceptor; + public interface IAspectCoreService //: EasyCaching.Core.Internal.IEasyCaching { [EasyCachingAble(Expiration = 10)] diff --git a/sample/EasyCaching.Demo.Interceptors/Services/ICastleService.cs b/sample/EasyCaching.Demo.Interceptors/Services/ICastleService.cs index 709052d2..2bfc560d 100644 --- a/sample/EasyCaching.Demo.Interceptors/Services/ICastleService.cs +++ b/sample/EasyCaching.Demo.Interceptors/Services/ICastleService.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Demo.Interceptors.Services { using System.Threading.Tasks; + using EasyCaching.Core.Interceptor; using EasyCaching.Core.Internal; public interface ICastleService diff --git a/sample/EasyCaching.Demo.Providers/Startup.cs b/sample/EasyCaching.Demo.Providers/Startup.cs index c2935895..4c41d77d 100644 --- a/sample/EasyCaching.Demo.Providers/Startup.cs +++ b/sample/EasyCaching.Demo.Providers/Startup.cs @@ -15,6 +15,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; + using EasyCaching.Core.Configurations; public class Startup { diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/ConnectionPooledObjectPolicy.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/ConnectionPooledObjectPolicy.cs new file mode 100644 index 00000000..25fe3c83 --- /dev/null +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/ConnectionPooledObjectPolicy.cs @@ -0,0 +1,58 @@ +namespace EasyCaching.Bus.RabbitMQ +{ + using Microsoft.Extensions.ObjectPool; + using Microsoft.Extensions.Options; + using global::RabbitMQ.Client; + + /// + /// Connection pooled object policy. + /// + public class ConnectionPooledObjectPolicy : IPooledObjectPolicy + { + /// + /// The options. + /// + private readonly RabbitMQBusOptions _options; + + /// + /// Initializes a new instance of the class. + /// + /// Options accs. + public ConnectionPooledObjectPolicy(IOptions optionsAccs) + { + this._options = optionsAccs.Value; + } + + /// + /// Create this instance. + /// + /// The create. + public IConnection Create() + { + var factory = new ConnectionFactory + { + HostName = _options.HostName, + UserName = _options.UserName, + Port = _options.Port, + Password = _options.Password, + VirtualHost = _options.VirtualHost, + RequestedConnectionTimeout = _options.RequestedConnectionTimeout, + SocketReadTimeout = _options.SocketReadTimeout, + SocketWriteTimeout = _options.SocketWriteTimeout + }; + + var connection = factory.CreateConnection(); + return connection; + } + + /// + /// Return the specified connection. + /// + /// The return. + /// Connection. + public bool Return(IConnection connection) + { + return true; + } + } +} \ No newline at end of file diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs new file mode 100644 index 00000000..a58a6829 --- /dev/null +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/EasyCachingOptionsExtensions.cs @@ -0,0 +1,62 @@ +namespace EasyCaching.Bus.RabbitMQ +{ + using System; + using EasyCaching.Core.Configurations; + using Microsoft.Extensions.Configuration; + + /// + /// EasyCaching options extensions. + /// + public static class EasyCachingOptionsExtensions + { + /// + /// Withs the RabbitMQ Bus. + /// + /// The rabbit MQB us. + /// Options. + /// Configure. + public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + options.RegisterExtension(new RabbitMQBusOptionsExtension(configure)); + return options; + } + + /// + /// Withs the RabbitMQ Bus. + /// + /// The rabbit MQB us. + /// Options. + /// Configuration. + /// Section name. + public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "rabbitmqbus") + { + var dbConfig = configuration.GetSection(sectionName); + var busOptions = new RabbitMQBusOptions(); + dbConfig.Bind(busOptions); + + void configure(RabbitMQBusOptions x) + { + x.HostName = busOptions.HostName; + x.Password = busOptions.Password; + x.Port = busOptions.Port; + x.QueueMessageExpires = busOptions.QueueMessageExpires; + x.RequestedConnectionTimeout = busOptions.RequestedConnectionTimeout; + x.RouteKey = busOptions.RouteKey; + x.SocketReadTimeout = busOptions.SocketReadTimeout; + x.SocketWriteTimeout = busOptions.SocketWriteTimeout; + x.TopicExchangeName = busOptions.TopicExchangeName; + x.UserName = busOptions.UserName; + x.VirtualHost = busOptions.VirtualHost; + x.QueueName = busOptions.QueueName; + } + + options.RegisterExtension(new RabbitMQBusOptionsExtension(configure)); + return options; + } + } +} diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs new file mode 100644 index 00000000..bf0da3d2 --- /dev/null +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptions.cs @@ -0,0 +1,22 @@ +namespace EasyCaching.Bus.RabbitMQ +{ + using EasyCaching.Core.Configurations; + + /// + /// RabbitMQ Bus options. + /// + public class RabbitMQBusOptions : BaseRabbitMQOptions + { + /// + /// Gets or sets the route key. + /// + /// The route key. + public string RouteKey { get; set; } = "rmq.queue.undurable.easycaching.subscriber.*"; + + /// + /// Gets or sets the name of the queue. + /// + /// The name of the queue. + public string QueueName { get; set; } = ""; + } +} diff --git a/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptionsExtension.cs b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptionsExtension.cs new file mode 100644 index 00000000..d0c88067 --- /dev/null +++ b/src/EasyCaching.Bus.RabbitMQ/Configurations/RabbitMQBusOptionsExtension.cs @@ -0,0 +1,55 @@ +namespace EasyCaching.Bus.RabbitMQ +{ + using System; + using EasyCaching.Core.Bus; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; + using global::RabbitMQ.Client; + using Microsoft.AspNetCore.Builder; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.DependencyInjection.Extensions; + using Microsoft.Extensions.ObjectPool; + + /// + /// RabbitMQ Bus options extension. + /// + public class RabbitMQBusOptionsExtension : IEasyCachingOptionsExtension + { + /// + /// The configure. + /// + private readonly Action configure; + + /// + /// Initializes a new instance of the class. + /// + /// Configure. + public RabbitMQBusOptionsExtension(Action configure) + { + this.configure = configure; + } + + /// + /// Adds the services. + /// + /// Services. + public void AddServices(IServiceCollection services) + { + services.AddOptions(); + services.Configure(configure); + + services.TryAddSingleton(); + services.AddSingleton, ConnectionPooledObjectPolicy>(); + services.AddSingleton(); + } + + /// + /// Withs the services. + /// + /// Services. + public void WithServices(IApplicationBuilder services) + { + // Method intentionally left empty. + } + } +} diff --git a/src/EasyCaching.Bus.RabbitMQ/ConnectionChannelPool.cs b/src/EasyCaching.Bus.RabbitMQ/ConnectionChannelPool.cs deleted file mode 100644 index ff6795da..00000000 --- a/src/EasyCaching.Bus.RabbitMQ/ConnectionChannelPool.cs +++ /dev/null @@ -1,168 +0,0 @@ -namespace EasyCaching.Bus.RabbitMQ -{ - using System; - using System.Collections.Concurrent; - using System.Threading; - using global::RabbitMQ.Client; - - /// - /// Connection channel pool. - /// - public class ConnectionChannelPool : IConnectionChannelPool, IDisposable - { - /// - /// The default size of the pool. - /// - private const int DefaultPoolSize = 15; - /// - /// The connection activator. - /// - private readonly Func _connectionActivator; - /// - /// The pool. - /// - private readonly ConcurrentQueue _pool = new ConcurrentQueue(); - /// - /// The connection. - /// - private IConnection _connection; - /// - /// The count. - /// - private int _count; - /// - /// The size of the max. - /// - private int _maxSize; - - /// - /// Initializes a new instance of the class. - /// - /// Options. - public ConnectionChannelPool(RabbitMQBusOptions options) - { - _maxSize = DefaultPoolSize; - - _connectionActivator = CreateConnection(options); - } - - /// - /// - /// - /// - IModel IConnectionChannelPool.Rent() - { - return Rent(); - } - - /// - /// Easies the caching. bus. rabbit MQ . IC onnection channel pool. return. - /// - /// true, if caching. bus. rabbit MQ . IC onnection channel pool. return was easyed, false otherwise. - /// Connection. - bool IConnectionChannelPool.Return(IModel connection) - { - return Return(connection); - } - - /// - /// Gets the connection. - /// - /// The connection. - public IConnection GetConnection() - { - if (_connection != null && _connection.IsOpen) - return _connection; - _connection = _connectionActivator(); - _connection.ConnectionShutdown += RabbitMQ_ConnectionShutdown; - return _connection; - } - - /// - /// Releases all resource used by the object. - /// - /// Call when you are finished using the - /// . The method leaves the - /// in an unusable state. After calling - /// , you must release all references to the - /// so the garbage collector can reclaim the - /// memory that the was occupying. - public void Dispose() - { - _maxSize = 0; - - while (_pool.TryDequeue(out var context)) - context.Dispose(); - } - - /// - /// Creates the connection. - /// - /// The connection. - /// Options. - private static Func CreateConnection(RabbitMQBusOptions options) - { - var factory = new ConnectionFactory - { - HostName = options.HostName, - UserName = options.UserName, - Port = options.Port, - Password = options.Password, - VirtualHost = options.VirtualHost, - RequestedConnectionTimeout = options.RequestedConnectionTimeout, - SocketReadTimeout = options.SocketReadTimeout, - SocketWriteTimeout = options.SocketWriteTimeout - }; - - return () => factory.CreateConnection(); - } - - /// - /// Rabbits the mq connection shutdown. - /// - /// Sender. - /// E. - private void RabbitMQ_ConnectionShutdown(object sender, ShutdownEventArgs e) - { - Console.WriteLine("closed!"); - } - - /// - /// Rent this instance. - /// - /// The rent. - public virtual IModel Rent() - { - if (_pool.TryDequeue(out var model)) - { - Interlocked.Decrement(ref _count); - - return model; - } - - model = GetConnection().CreateModel(); - - return model; - } - - /// - /// Return the specified connection. - /// - /// The return. - /// Connection. - public virtual bool Return(IModel connection) - { - if (Interlocked.Increment(ref _count) <= _maxSize) - { - _pool.Enqueue(connection); - - return true; - } - - Interlocked.Decrement(ref _count); - - return false; - } - } - -} diff --git a/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs b/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs index 1c53ded3..a8c178ae 100644 --- a/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs +++ b/src/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs @@ -1,12 +1,13 @@ namespace EasyCaching.Bus.RabbitMQ { - using EasyCaching.Core; - using EasyCaching.Core.Internal; using System; + using System.Threading; using System.Threading.Tasks; - using System.Collections.Generic; - using global::RabbitMQ.Client.Events; + using EasyCaching.Core.Bus; + using EasyCaching.Core.Serialization; using global::RabbitMQ.Client; + using global::RabbitMQ.Client.Events; + using Microsoft.Extensions.ObjectPool; /// /// Default RabbitMQ Bus. @@ -14,14 +15,24 @@ public class DefaultRabbitMQBus : IEasyCachingBus { /// - /// The connection channel pool. + /// The subscriber connection. + /// + private readonly IConnection _subConnection; + + /// + /// The publish connection pool. + /// + private readonly ObjectPool _pubConnectionPool; + + /// + /// The handler. /// - private readonly IConnectionChannelPool _connectionChannelPool; + private Action _handler; /// /// The rabbitMQ Bus options. /// - private readonly RabbitMQBusOptions _rabbitMQBusOptions; + private readonly RabbitMQBusOptions _options; /// /// The serializer. @@ -29,44 +40,59 @@ public class DefaultRabbitMQBus : IEasyCachingBus private readonly IEasyCachingSerializer _serializer; /// - /// The local caching provider. + /// The identifier. /// - private readonly IEasyCachingProvider _localCachingProvider; + private readonly string _busId; /// /// Initializes a new instance of the class. /// - /// Connection channel pool. - /// Rabbit MQO ptions. + /// Object policy. + /// RabbitMQ Options. /// Serializer. - /// Local caching provider. public DefaultRabbitMQBus( - IConnectionChannelPool connectionChannelPool, - RabbitMQBusOptions rabbitMQOptions, - IEasyCachingSerializer serializer, - IEasyCachingProvider localCachingProvider) + IPooledObjectPolicy _objectPolicy + ,RabbitMQBusOptions rabbitMQOptions + ,IEasyCachingSerializer serializer) { - this._rabbitMQBusOptions = rabbitMQOptions; - this._connectionChannelPool = connectionChannelPool; + this._options = rabbitMQOptions; this._serializer = serializer; - this._localCachingProvider = localCachingProvider; + + var factory = new ConnectionFactory + { + HostName = _options.HostName, + UserName = _options.UserName, + Port = _options.Port, + Password = _options.Password, + VirtualHost = _options.VirtualHost, + RequestedConnectionTimeout = _options.RequestedConnectionTimeout, + SocketReadTimeout = _options.SocketReadTimeout, + SocketWriteTimeout = _options.SocketWriteTimeout + }; + + _subConnection = factory.CreateConnection(); + + _pubConnectionPool = new DefaultObjectPool(_objectPolicy); + + _busId = Guid.NewGuid().ToString("N"); } - + /// - /// Publish the specified channel and message. + /// Publish the specified topic and message. /// - /// The publish. - /// Channel. + /// Topic. /// Message. - public void Publish(string channel, EasyCachingMessage message) + public void Publish(string topic, EasyCachingMessage message) { - var _publisherChannel = _connectionChannelPool.Rent(); + var conn = _pubConnectionPool.Get(); + try - { + { var body = _serializer.Serialize(message); + var model = conn.CreateModel(); - _publisherChannel.ExchangeDeclare(_rabbitMQBusOptions.TopicExchangeName, ExchangeType.Topic, true, false, null); - _publisherChannel.BasicPublish(_rabbitMQBusOptions.TopicExchangeName, channel, false, null, body); + model.ExchangeDeclare(_options.TopicExchangeName, ExchangeType.Topic, true, false, null); + model.BasicPublish(_options.TopicExchangeName, topic, false, null, body); } catch (Exception ex) { @@ -74,80 +100,93 @@ public void Publish(string channel, EasyCachingMessage message) } finally { - var returned = _connectionChannelPool.Return(_publisherChannel); - if (!returned) - _publisherChannel.Dispose(); + _pubConnectionPool.Return(conn); } } /// - /// Publishs the async. + /// Publish the specified topic and message async. /// /// The async. - /// Channel. + /// Topic. /// Message. - public Task PublishAsync(string channel, EasyCachingMessage message) + /// Cancellation token. + public Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken)) { - throw new NotImplementedException(); - } + var conn = _pubConnectionPool.Get(); + try + { + var body = _serializer.Serialize(message); + var model = conn.CreateModel(); + model.ExchangeDeclare(_options.TopicExchangeName, ExchangeType.Topic, true, false, null); + model.BasicPublish(_options.TopicExchangeName, topic, false, null, body); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + _pubConnectionPool.Return(conn); + } + return Task.CompletedTask; + } + /// - /// Subscribe the specified channel. + /// Subscribe the specified topic and action. /// - /// The subscribe. - /// Channel. - public void Subscribe(string channel) + /// Topic. + /// Action. + public void Subscribe(string topic, Action action) { - var _connection = _connectionChannelPool.GetConnection(); - - var _subscriberChannel = _connection.CreateModel(); - - _subscriberChannel.ExchangeDeclare(_rabbitMQBusOptions.TopicExchangeName, ExchangeType.Topic, true, true, null); - - var arguments = new Dictionary { - { "x-message-ttl", _rabbitMQBusOptions.QueueMessageExpires } - }; - - _subscriberChannel.QueueDeclare("easycaching.queue", true, false, false, arguments); - - var consumer = new EventingBasicConsumer(_subscriberChannel); - consumer.Received += OnConsumerReceived; - //consumer.Shutdown += OnConsumerShutdown; + _handler = action; + var queueName = string.Empty; + if(string.IsNullOrWhiteSpace(_options.QueueName)) + { + queueName = $"rmq.queue.undurable.easycaching.subscriber.{_busId}"; + } + else + { + queueName = _options.QueueName; + } - _subscriberChannel.BasicConsume("easycaching.queue", false, string.Empty, false, false, null, consumer); + 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); + var consumer = new EventingBasicConsumer(model); + consumer.Received += OnMessage; + consumer.Shutdown += OnConsumerShutdown; + + model.BasicConsume(queueName, true, consumer); + + }, TaskCreationOptions.LongRunning); } /// - /// Subscribes the async. + /// Ons the consumer shutdown. /// - /// The async. - /// Channel. - public Task SubscribeAsync(string channel) + /// Sender. + /// E. + private void OnConsumerShutdown(object sender, ShutdownEventArgs e) { - throw new NotImplementedException(); + Console.WriteLine($"{e.ReplyText}"); } /// - /// Consumers the received. + /// Ons the message. /// /// Sender. /// E. - private void OnConsumerReceived(object sender, BasicDeliverEventArgs e) + private void OnMessage(object sender, BasicDeliverEventArgs e) { - var message = _serializer.Deserialize(e.Body); + var message = _serializer.Deserialize(e.Body); - switch (message.NotifyType) - { - case NotifyType.Add: - _localCachingProvider.Set(message.CacheKey, message.CacheValue, message.Expiration); - break; - case NotifyType.Update: - _localCachingProvider.Refresh(message.CacheKey, message.CacheValue, message.Expiration); - break; - case NotifyType.Delete: - _localCachingProvider.Remove(message.CacheKey); - break; - } + _handler?.Invoke(message); } } } diff --git a/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj b/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj index 689feaa3..0871cb3b 100644 --- a/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj +++ b/src/EasyCaching.Bus.RabbitMQ/EasyCaching.Bus.RabbitMQ.csproj @@ -4,17 +4,19 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.0 - - EasyCaching is a open source caching library that contains basic opreations of caching. + $(EasyCachingRabbitBusPackageVersion) + + A simple caching bus(message bus) based on RabbitMQ. - Caching,Cache,Distributed Cache,Memory Cache,Interceptor,Synchronization - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/easycaching-icon.png - + Bus,Hybrid,RabbitMQ,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/easycaching-icon.png + + $(EasyCachingRabbitBusPackageNotes) + @@ -23,5 +25,9 @@ + + + + diff --git a/src/EasyCaching.Bus.RabbitMQ/IConnectionChannelPool.cs b/src/EasyCaching.Bus.RabbitMQ/IConnectionChannelPool.cs deleted file mode 100644 index 60f7aeed..00000000 --- a/src/EasyCaching.Bus.RabbitMQ/IConnectionChannelPool.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace EasyCaching.Bus.RabbitMQ -{ - using global::RabbitMQ.Client; - - /// - /// Connection channel pool. - /// - public interface IConnectionChannelPool - { - /// - /// Gets the connection. - /// - /// The connection. - IConnection GetConnection(); - - /// - /// Rent this instance. - /// - /// The rent. - IModel Rent(); - - /// - /// Return the specified context. - /// - /// The return. - /// Context. - bool Return(IModel context); - } -} diff --git a/src/EasyCaching.Bus.RabbitMQ/RabbitMQBusOptions.cs b/src/EasyCaching.Bus.RabbitMQ/RabbitMQBusOptions.cs deleted file mode 100644 index e3362857..00000000 --- a/src/EasyCaching.Bus.RabbitMQ/RabbitMQBusOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace EasyCaching.Bus.RabbitMQ -{ - using EasyCaching.Core.Internal; - - /// - /// RabbitMQ Bus options. - /// - public class RabbitMQBusOptions : BaseRabbitMQOptions - { - } -} diff --git a/src/EasyCaching.Bus.RabbitMQ/RabbitMQBusServiceCollectionExtensions.cs b/src/EasyCaching.Bus.RabbitMQ/RabbitMQBusServiceCollectionExtensions.cs deleted file mode 100644 index 95a48491..00000000 --- a/src/EasyCaching.Bus.RabbitMQ/RabbitMQBusServiceCollectionExtensions.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace EasyCaching.Bus.RabbitMQ -{ - using EasyCaching.Core; - using EasyCaching.Core.Internal; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.DependencyInjection.Extensions; - using System; - - /// - /// RabbitMQ Bus service collection extensions. - /// - public static class RabbitMQBusServiceCollectionExtensions - { - /// - /// Adds the default rabbitMQ Bus. - /// - /// The default rabbit MQB us. - /// Services. - /// Options action. - public static IServiceCollection AddDefaultRabbitMQBus(this IServiceCollection services, Action optionsAction) - { - ArgumentCheck.NotNull(services, nameof(services)); - ArgumentCheck.NotNull(optionsAction, nameof(optionsAction)); - - var options = new RabbitMQBusOptions(); - optionsAction?.Invoke(options); - services.AddSingleton(options); - - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - - return services; - } - } -} diff --git a/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs new file mode 100644 index 00000000..0c5192e5 --- /dev/null +++ b/src/EasyCaching.Bus.Redis/Configurations/EasyCachingOptionsExtensions.cs @@ -0,0 +1,60 @@ +namespace EasyCaching.Bus.Redis +{ + using System; + 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 WithRedisBus(this EasyCachingOptions options, Action configure) + { + if (configure == null) + { + throw new ArgumentNullException(nameof(configure)); + } + + options.RegisterExtension(new RedisBusOptionsExtension(configure)); + return options; + } + + /// + /// Withs the redis bus. + /// + /// The redis bus. + /// Options. + /// Configuration. + /// Section name. + public static EasyCachingOptions WithRedisBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "redisbus") + { + var dbConfig = configuration.GetSection(sectionName); + var redisOptions = new RedisBusOptions(); + dbConfig.Bind(redisOptions); + + void configure(RedisBusOptions x) + { + x.AbortOnConnectFail = redisOptions.AbortOnConnectFail; + x.AllowAdmin = redisOptions.AllowAdmin; + x.Configuration = redisOptions.Configuration; + x.ConnectionTimeout = redisOptions.ConnectionTimeout; + x.Database = redisOptions.Database; + x.IsSsl = redisOptions.IsSsl; + x.Password = redisOptions.Password; + x.SslHost = redisOptions.SslHost; + + foreach (var item in redisOptions.Endpoints) x.Endpoints.Add(item); + } + + options.RegisterExtension(new RedisBusOptionsExtension(configure)); + return options; + } + } +} diff --git a/src/EasyCaching.Bus.Redis/IRedisSubscriberProvider.cs b/src/EasyCaching.Bus.Redis/Configurations/IRedisSubscriberProvider.cs similarity index 100% rename from src/EasyCaching.Bus.Redis/IRedisSubscriberProvider.cs rename to src/EasyCaching.Bus.Redis/Configurations/IRedisSubscriberProvider.cs diff --git a/src/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs b/src/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs new file mode 100644 index 00000000..46bcdb6f --- /dev/null +++ b/src/EasyCaching.Bus.Redis/Configurations/RedisBusOptions.cs @@ -0,0 +1,16 @@ +namespace EasyCaching.Bus.Redis +{ + using EasyCaching.Core.Configurations; + + /// + /// Redis bus options. + /// + public class RedisBusOptions : BaseRedisOptions + { + /// + /// Gets or sets the database. + /// + /// The database. + public int Database { get; set; } = 0; + } +} diff --git a/src/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs b/src/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs new file mode 100644 index 00000000..a8333f7e --- /dev/null +++ b/src/EasyCaching.Bus.Redis/Configurations/RedisBusOptionsExtension.cs @@ -0,0 +1,53 @@ +namespace EasyCaching.Bus.Redis +{ + 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; + + /// + /// Redis bus options extension. + /// + internal sealed class RedisBusOptionsExtension : IEasyCachingOptionsExtension + { + /// + /// The configure. + /// + private readonly Action configure; + + /// + /// Initializes a new instance of the class. + /// + /// Configure. + public RedisBusOptionsExtension(Action configure) + { + this.configure = configure; + } + + /// + /// Adds the services. + /// + /// Services. + public void AddServices(IServiceCollection services) + { + services.AddOptions(); + services.Configure(configure); + + services.TryAddSingleton(); + services.TryAddSingleton(); + services.AddSingleton(); + } + + /// + /// Withs the services. + /// + /// Services. + public void WithServices(IApplicationBuilder services) + { + // Method intentionally left empty. + } + } +} diff --git a/src/EasyCaching.Bus.Redis/RedisSubscriberProvider.cs b/src/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs similarity index 50% rename from src/EasyCaching.Bus.Redis/RedisSubscriberProvider.cs rename to src/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs index c00b18f0..6e1dbd01 100644 --- a/src/EasyCaching.Bus.Redis/RedisSubscriberProvider.cs +++ b/src/EasyCaching.Bus.Redis/Configurations/RedisSubscriberProvider.cs @@ -1,12 +1,13 @@ namespace EasyCaching.Bus.Redis { + using Microsoft.Extensions.Options; using StackExchange.Redis; using System; /// /// Redis database provider. /// - public class RedisSubscriberProvider : IRedisSubscriberProvider + internal class RedisSubscriberProvider : IRedisSubscriberProvider { /// /// The options. @@ -19,12 +20,12 @@ public class RedisSubscriberProvider : IRedisSubscriberProvider private readonly Lazy _connectionMultiplexer; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Options. - public RedisSubscriberProvider(RedisBusOptions options) + public RedisSubscriberProvider(IOptions options) { - _options = options; + _options = options.Value; _connectionMultiplexer = new Lazy(CreateConnectionMultiplexer); } @@ -42,20 +43,30 @@ public ISubscriber GetSubscriber() /// The connection multiplexer. private ConnectionMultiplexer CreateConnectionMultiplexer() { - var configurationOptions = new ConfigurationOptions + if (string.IsNullOrWhiteSpace(_options.Configuration)) { - ConnectTimeout = _options.ConnectionTimeout, - Password = _options.Password, - Ssl = _options.IsSsl, - SslHost = _options.SslHost, - }; + var configurationOptions = new ConfigurationOptions + { + ConnectTimeout = _options.ConnectionTimeout, + Password = _options.Password, + Ssl = _options.IsSsl, + SslHost = _options.SslHost, + AllowAdmin = _options.AllowAdmin, + DefaultDatabase = _options.Database, + AbortOnConnectFail = _options.AbortOnConnectFail, + }; - foreach (var endpoint in _options.Endpoints) + foreach (var endpoint in _options.Endpoints) + { + configurationOptions.EndPoints.Add(endpoint.Host, endpoint.Port); + } + + return ConnectionMultiplexer.Connect(configurationOptions.ToString()); + } + else { - configurationOptions.EndPoints.Add(endpoint.Host, endpoint.Port); + return ConnectionMultiplexer.Connect(_options.Configuration); } - - return ConnectionMultiplexer.Connect(configurationOptions.ToString()); } } } diff --git a/src/EasyCaching.Bus.Redis/DefaultRedisBus.cs b/src/EasyCaching.Bus.Redis/DefaultRedisBus.cs index b6e24146..15bfc92a 100644 --- a/src/EasyCaching.Bus.Redis/DefaultRedisBus.cs +++ b/src/EasyCaching.Bus.Redis/DefaultRedisBus.cs @@ -1,8 +1,11 @@ namespace EasyCaching.Bus.Redis { using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Bus; + using EasyCaching.Core.Serialization; using StackExchange.Redis; + using System; + using System.Threading; using System.Threading.Tasks; /// @@ -21,98 +24,76 @@ public class DefaultRedisBus : IEasyCachingBus private readonly IRedisSubscriberProvider _subscriberProvider; /// - /// The serializer. + /// The handler. /// - private readonly IEasyCachingSerializer _serializer; + private Action _handler; /// - /// The local caching provider. + /// The serializer. /// - private readonly IEasyCachingProvider _localCachingProvider; + private readonly IEasyCachingSerializer _serializer; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Subscriber provider. + /// Serializer. public DefaultRedisBus( IRedisSubscriberProvider subscriberProvider, - IEasyCachingSerializer serializer, - IEasyCachingProvider localCachingProvider) + IEasyCachingSerializer serializer) { this._subscriberProvider = subscriberProvider; this._serializer = serializer; - this._localCachingProvider = localCachingProvider; - this._subscriber = _subscriberProvider.GetSubscriber(); } - /// - /// Subscribe the specified channel and notifyType. - /// - /// The subscribe. - /// Channel. - public void Subscribe(string channel) - { - _subscriber.Subscribe(channel, SubscribeHandle); - } - /// /// Subscribes the handle. /// /// Channel. /// Value. - private void SubscribeHandle(RedisChannel channel, RedisValue value) + private void OnMessage(RedisChannel channel, RedisValue value) { var message = _serializer.Deserialize(value); - switch (message.NotifyType) - { - case NotifyType.Add: - _localCachingProvider.Set(message.CacheKey, message.CacheValue, message.Expiration); - break; - case NotifyType.Update: - _localCachingProvider.Refresh(message.CacheKey, message.CacheValue, message.Expiration); - break; - case NotifyType.Delete: - _localCachingProvider.Remove(message.CacheKey); - break; - } + _handler?.Invoke(message); } /// - /// Subscribes the async. + /// Publish the specified topic and message. /// - /// The async. - /// Channel. - public async Task SubscribeAsync(string channel) + /// Topic. + /// Message. + public void Publish(string topic, EasyCachingMessage message) { - await _subscriber.SubscribeAsync(channel, SubscribeHandle); + ArgumentCheck.NotNullOrWhiteSpace(topic, nameof(topic)); + + _subscriber.Publish(topic, _serializer.Serialize(message)); } /// - /// Publish the specified channel and message. + /// Publishs the specified topic and message async. /// - /// The publish. - /// Channel. + /// The async. + /// Topic. /// Message. - public void Publish(string channel, EasyCachingMessage message) + /// Cancellation token. + public async Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken)) { - ArgumentCheck.NotNullOrWhiteSpace(channel, nameof(channel)); + ArgumentCheck.NotNullOrWhiteSpace(topic, nameof(topic)); - _subscriber.Publish(channel, _serializer.Serialize(message)); + await _subscriber.PublishAsync(topic, _serializer.Serialize(message)); } /// - /// Publishs the async. + /// Subscribe the specified topic and action. /// - /// The async. - /// Channel. - /// Message. - public async Task PublishAsync(string channel, EasyCachingMessage message) + /// Topic. + /// Action. + public void Subscribe(string topic, Action action) { - ArgumentCheck.NotNullOrWhiteSpace(channel, nameof(channel)); - - await _subscriber.PublishAsync(channel, _serializer.Serialize(message)); + _handler = action; + _subscriber.Subscribe(topic, OnMessage); } } } diff --git a/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj b/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj index 294d8dd9..5ef428bf 100644 --- a/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj +++ b/src/EasyCaching.Bus.Redis/EasyCaching.Bus.Redis.csproj @@ -4,24 +4,29 @@ netstandard2.0 Catcher Wong Catcher Wong - 0.1.0 - - EasyCaching is a open source caching library that contains basic opreations of caching. + $(EasyCachingRedisBusPackageVersion) + + A simple caching bus(message bus) based on StackExchange.Redis. - Caching,Cache,Distributed Cache,Memory Cache,Interceptor,Synchronization - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching/blob/master/LICENSE - https://github.com/catcherwong/EasyCaching - https://github.com/catcherwong/EasyCaching - https://raw.githubusercontent.com/catcherwong/EasyCaching/master/media/easycaching-icon.png - + 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/easycaching-icon.png + + $(EasyCachingRedisBusPackageNotes) + - + + + + diff --git a/src/EasyCaching.Bus.Redis/RedisBusOptions.cs b/src/EasyCaching.Bus.Redis/RedisBusOptions.cs deleted file mode 100644 index b06e3474..00000000 --- a/src/EasyCaching.Bus.Redis/RedisBusOptions.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace EasyCaching.Bus.Redis -{ - using EasyCaching.Core.Internal; - - public class RedisBusOptions : BaseRedisOptions - { - - } -} diff --git a/src/EasyCaching.Bus.Redis/RedisBusServiceCollectionExtensions.cs b/src/EasyCaching.Bus.Redis/RedisBusServiceCollectionExtensions.cs deleted file mode 100644 index d0ca7f73..00000000 --- a/src/EasyCaching.Bus.Redis/RedisBusServiceCollectionExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace EasyCaching.Bus.Redis -{ - using EasyCaching.Core; - using EasyCaching.Core.Internal; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.DependencyInjection.Extensions; - using System; - - /// - /// Redis bus service collection extensions. - /// - public static class RedisBusServiceCollectionExtensions - { - /// - /// Adds the default redis bus. - /// - /// The default redis bus. - /// Services. - /// Options action. - public static IServiceCollection AddDefaultRedisBus(this IServiceCollection services, Action optionsAction) - { - ArgumentCheck.NotNull(services, nameof(services)); - ArgumentCheck.NotNull(optionsAction, nameof(optionsAction)); - - var options = new RedisBusOptions(); - optionsAction?.Invoke(options); - services.AddSingleton(options); - - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - //services.TryAddSingleton(); - - return services; - } - } -} diff --git a/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs index 3f4fc825..908104f0 100644 --- a/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.CSRedis/Configurations/EasyCachingOptionsExtensions.cs @@ -1,9 +1,9 @@ namespace EasyCaching.CSRedis { + using System; using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; - using System; /// /// EasyCaching options extensions. diff --git a/src/EasyCaching.CSRedis/Configurations/RedisOptions.cs b/src/EasyCaching.CSRedis/Configurations/RedisOptions.cs index 4e2cd5a2..2e3f01d9 100755 --- a/src/EasyCaching.CSRedis/Configurations/RedisOptions.cs +++ b/src/EasyCaching.CSRedis/Configurations/RedisOptions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.CSRedis { using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; public class RedisOptions : BaseProviderOptions { diff --git a/src/EasyCaching.CSRedis/Configurations/RedisOptionsExtension.cs b/src/EasyCaching.CSRedis/Configurations/RedisOptionsExtension.cs index 3f47c11b..9d6e0495 100755 --- a/src/EasyCaching.CSRedis/Configurations/RedisOptionsExtension.cs +++ b/src/EasyCaching.CSRedis/Configurations/RedisOptionsExtension.cs @@ -1,6 +1,8 @@ namespace EasyCaching.CSRedis { using EasyCaching.Core; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -30,7 +32,7 @@ internal sealed class RedisOptionsExtension : IEasyCachingOptionsExtension /// Configure. public RedisOptionsExtension(string name, Action configure) { - Core.Internal.ArgumentCheck.NotNullOrWhiteSpace(name, nameof(name)); + ArgumentCheck.NotNullOrWhiteSpace(name, nameof(name)); this._name = name; this._configure = configure; diff --git a/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.cs b/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.cs index f3e7b8c4..33e0d35d 100644 --- a/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.cs +++ b/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.cs @@ -2,6 +2,7 @@ { using EasyCaching.Core; using EasyCaching.Core.Internal; + using EasyCaching.Core.Serialization; using global::CSRedis; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/EasyCaching.CSRedis/EasyCaching.CSRedis.csproj b/src/EasyCaching.CSRedis/EasyCaching.CSRedis.csproj index 750db734..ab111bce 100644 --- a/src/EasyCaching.CSRedis/EasyCaching.CSRedis.csproj +++ b/src/EasyCaching.CSRedis/EasyCaching.CSRedis.csproj @@ -7,9 +7,9 @@ Catcher Wong $(EasyCachingCSRedisPackageVersion) - EasyCaching.CSRedis based on EasyCaching.Core and CSRedisCore + A simple distributed caching provider based on csredis. - Caching,Cache,Distributed,Redis + Redis,DistributedCache,Caching,Cache https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Core/Bus/EasyCachingMessage.cs b/src/EasyCaching.Core/Bus/EasyCachingMessage.cs new file mode 100644 index 00000000..c8b86729 --- /dev/null +++ b/src/EasyCaching.Core/Bus/EasyCachingMessage.cs @@ -0,0 +1,23 @@ +namespace EasyCaching.Core.Bus +{ + using System; + + /// + /// EasyCaching message. + /// + [Serializable] + public class EasyCachingMessage + { + /// + /// Gets or sets the identifier. + /// + /// The identifier. + public string Id { get; set; } + + /// + /// Gets or sets the cache keys. + /// + /// The cache keys. + public string[] CacheKeys { get; set; } + } +} diff --git a/src/EasyCaching.Core/IEasyCachingBus.cs b/src/EasyCaching.Core/Bus/IEasyCachingBus.cs similarity index 82% rename from src/EasyCaching.Core/IEasyCachingBus.cs rename to src/EasyCaching.Core/Bus/IEasyCachingBus.cs index 5a6591fc..743b13a9 100644 --- a/src/EasyCaching.Core/IEasyCachingBus.cs +++ b/src/EasyCaching.Core/Bus/IEasyCachingBus.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Bus { /// /// Easycaching bus. diff --git a/src/EasyCaching.Core/Bus/IEasyCachingPublisher.cs b/src/EasyCaching.Core/Bus/IEasyCachingPublisher.cs new file mode 100644 index 00000000..a4e4c9c1 --- /dev/null +++ b/src/EasyCaching.Core/Bus/IEasyCachingPublisher.cs @@ -0,0 +1,27 @@ +namespace EasyCaching.Core.Bus +{ + using System.Threading; + using System.Threading.Tasks; + + /// + /// EasyCaching publisher. + /// + public interface IEasyCachingPublisher + { + /// + /// Publish the specified topic and message. + /// + /// Topic. + /// Message. + void Publish(string topic, EasyCachingMessage message); + + /// + /// Publishs the specified topic and message. + /// + /// The async. + /// Topic. + /// Message. + /// Cancellation token. + Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken)); + } +} diff --git a/src/EasyCaching.Core/Bus/IEasyCachingSubscriber.cs b/src/EasyCaching.Core/Bus/IEasyCachingSubscriber.cs new file mode 100644 index 00000000..768005ce --- /dev/null +++ b/src/EasyCaching.Core/Bus/IEasyCachingSubscriber.cs @@ -0,0 +1,17 @@ +namespace EasyCaching.Core.Bus +{ + using System; + + /// + /// EasyCaching subscriber. + /// + public interface IEasyCachingSubscriber + { + /// + /// Subscribe the specified topic and action. + /// + /// Topic. + /// Action. + void Subscribe(string topic, Action action); + } +} diff --git a/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs b/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs new file mode 100644 index 00000000..199744e7 --- /dev/null +++ b/src/EasyCaching.Core/Bus/NullEasyCachingBus.cs @@ -0,0 +1,60 @@ +namespace EasyCaching.Core.Bus +{ + using System; + using System.Threading; + using System.Threading.Tasks; + + /// + /// Null easy caching bus. + /// + public class NullEasyCachingBus : IEasyCachingBus + { + /// + /// The instance. + /// + public static readonly NullEasyCachingBus Instance = new NullEasyCachingBus(); + + /// + /// Releases all resource used by the object. + /// + /// Call when you are finished using the + /// . The method leaves the + /// in an unusable state. After calling + /// , you must release all references to the + /// so the garbage collector can reclaim the memory that + /// the was occupying. + public void Dispose() { } + + /// + /// Publish the specified topic and message. + /// + /// Topic. + /// Message. + public void Publish(string topic, EasyCachingMessage message) + { + + } + + /// + /// Publish the specified topic and message async. + /// + /// The async. + /// Topic. + /// Message. + /// Cancellation token. + public Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken)) + { + return Task.CompletedTask; + } + + /// + /// Subscribe the specified topic and action. + /// + /// Topic. + /// Action. + public void Subscribe(string topic, Action action) + { + + } + } +} diff --git a/src/EasyCaching.Core/Internal/BaseProviderOptions.cs b/src/EasyCaching.Core/Configurations/BaseProviderOptions.cs similarity index 97% rename from src/EasyCaching.Core/Internal/BaseProviderOptions.cs rename to src/EasyCaching.Core/Configurations/BaseProviderOptions.cs index adbb186b..6c60fbe9 100644 --- a/src/EasyCaching.Core/Internal/BaseProviderOptions.cs +++ b/src/EasyCaching.Core/Configurations/BaseProviderOptions.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core.Configurations { /// /// Base provider options. diff --git a/src/EasyCaching.Core/Internal/BaseRabbitMQOptions.cs b/src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs similarity index 92% rename from src/EasyCaching.Core/Internal/BaseRabbitMQOptions.cs rename to src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs index 8f012a56..aae147f1 100644 --- a/src/EasyCaching.Core/Internal/BaseRabbitMQOptions.cs +++ b/src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core.Configurations { public class BaseRabbitMQOptions { @@ -25,7 +25,7 @@ public class BaseRabbitMQOptions /// /// Topic exchange name when declare a topic exchange. /// - public string TopicExchangeName { get; set; } = "easycaching.exchange"; + public string TopicExchangeName { get; set; } = "rmq.exchange.topic.easycaching"; /// /// Timeout setting for connection attempts (in milliseconds). diff --git a/src/EasyCaching.Core/Internal/BaseRedisOptions.cs b/src/EasyCaching.Core/Configurations/BaseRedisOptions.cs similarity index 98% rename from src/EasyCaching.Core/Internal/BaseRedisOptions.cs rename to src/EasyCaching.Core/Configurations/BaseRedisOptions.cs index 5166d34e..79ddf13c 100644 --- a/src/EasyCaching.Core/Internal/BaseRedisOptions.cs +++ b/src/EasyCaching.Core/Configurations/BaseRedisOptions.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core.Configurations { using System.Collections.Generic; diff --git a/src/EasyCaching.Core/Configurations/EasyCachingApplicationBuliderExtensions.cs b/src/EasyCaching.Core/Configurations/EasyCachingApplicationBuliderExtensions.cs index 4929d1dd..c7daae67 100644 --- a/src/EasyCaching.Core/Configurations/EasyCachingApplicationBuliderExtensions.cs +++ b/src/EasyCaching.Core/Configurations/EasyCachingApplicationBuliderExtensions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.Core { + using EasyCaching.Core.Configurations; using Microsoft.AspNetCore.Builder; - using System; public static class EasyCachingApplicationBuliderExtensions { @@ -12,10 +12,7 @@ public static class EasyCachingApplicationBuliderExtensions /// App. public static IApplicationBuilder UseEasyCaching(this IApplicationBuilder app) { - if (app == null) - { - throw new ArgumentNullException(nameof(app)); - } + ArgumentCheck.NotNull(app, nameof(app)); var options = app.ApplicationServices.GetService(typeof(EasyCachingOptions)); diff --git a/src/EasyCaching.Core/Configurations/EasyCachingOptions.cs b/src/EasyCaching.Core/Configurations/EasyCachingOptions.cs index 09bac17a..4a972435 100644 --- a/src/EasyCaching.Core/Configurations/EasyCachingOptions.cs +++ b/src/EasyCaching.Core/Configurations/EasyCachingOptions.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Configurations { using System.Collections.Generic; @@ -27,7 +27,7 @@ public EasyCachingOptions() /// Extension. public void RegisterExtension(IEasyCachingOptionsExtension extension) { - Internal.ArgumentCheck.NotNull(extension, nameof(extension)); + ArgumentCheck.NotNull(extension, nameof(extension)); Extensions.Add(extension); } diff --git a/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs b/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs index b6c5f856..2e433b4a 100644 --- a/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs +++ b/src/EasyCaching.Core/Configurations/EasyCachingServiceCollectionExtensions.cs @@ -1,13 +1,14 @@ namespace EasyCaching.Core { - using Microsoft.Extensions.DependencyInjection; using System; + using EasyCaching.Core.Configurations; + using Microsoft.Extensions.DependencyInjection; /// /// EasyCaching service collection extensions. /// public static class EasyCachingServiceCollectionExtensions - { + { /// /// Adds the easycaching. /// @@ -16,10 +17,7 @@ public static class EasyCachingServiceCollectionExtensions /// Setup action. public static IServiceCollection AddEasyCaching(this IServiceCollection services, Action setupAction) { - if (setupAction == null) - { - throw new ArgumentNullException(nameof(setupAction)); - } + ArgumentCheck.NotNull(setupAction, nameof(setupAction)); //Options and extension service var options = new EasyCachingOptions(); @@ -29,7 +27,7 @@ public static IServiceCollection AddEasyCaching(this IServiceCollection services serviceExtension.AddServices(services); } services.AddSingleton(options); - + return services; } } diff --git a/src/EasyCaching.Core/Configurations/IEasyCachingOptionsExtension.cs b/src/EasyCaching.Core/Configurations/IEasyCachingOptionsExtension.cs index e864df0e..4b4222e8 100644 --- a/src/EasyCaching.Core/Configurations/IEasyCachingOptionsExtension.cs +++ b/src/EasyCaching.Core/Configurations/IEasyCachingOptionsExtension.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Configurations { using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; diff --git a/src/EasyCaching.Core/Internal/ServerEndPoint.cs b/src/EasyCaching.Core/Configurations/ServerEndPoint.cs similarity index 87% rename from src/EasyCaching.Core/Internal/ServerEndPoint.cs rename to src/EasyCaching.Core/Configurations/ServerEndPoint.cs index 90cd817b..35c1d7c2 100644 --- a/src/EasyCaching.Core/Internal/ServerEndPoint.cs +++ b/src/EasyCaching.Core/Configurations/ServerEndPoint.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core.Configurations { /// /// Defines an endpoint. @@ -6,7 +6,7 @@ public class ServerEndPoint { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Host. /// Port. @@ -19,7 +19,7 @@ public ServerEndPoint(string host, int port) } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public ServerEndPoint() { diff --git a/src/EasyCaching.Core/EasyCaching.Core.csproj b/src/EasyCaching.Core/EasyCaching.Core.csproj index cafa2054..b10c256d 100644 --- a/src/EasyCaching.Core/EasyCaching.Core.csproj +++ b/src/EasyCaching.Core/EasyCaching.Core.csproj @@ -9,7 +9,7 @@ EasyCaching is a open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier! - Caching,Cache,Distributed,Memory,Interceptor,Synchronization,Hybrid + Caching,Cache,Distributed,Memory,Interceptor,Hybrid,ResponseCaching https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching @@ -23,6 +23,11 @@ + + + + + diff --git a/src/EasyCaching.Core/EasyCachingMessage.cs b/src/EasyCaching.Core/EasyCachingMessage.cs deleted file mode 100644 index ee2921da..00000000 --- a/src/EasyCaching.Core/EasyCachingMessage.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace EasyCaching.Core -{ - using EasyCaching.Core.Internal; - using System; - - public class EasyCachingMessage - { - public string CacheKey { get; set; } - - public object CacheValue { get; set; } - - public TimeSpan Expiration { get; set; } - - public NotifyType NotifyType { get; set; } - } -} diff --git a/src/EasyCaching.Core/IEasyCachingProviderFactory.cs b/src/EasyCaching.Core/IEasyCachingProviderFactory.cs deleted file mode 100644 index 1badf221..00000000 --- a/src/EasyCaching.Core/IEasyCachingProviderFactory.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace EasyCaching.Core -{ - using System.Collections.Generic; - using System.Linq; - - public interface IEasyCachingProviderFactory - { - IEasyCachingProvider GetCachingProvider(string name); - } - - public class DefaultEasyCachingProviderFactory : IEasyCachingProviderFactory - { - private readonly IEnumerable _cachingProviders; - - public DefaultEasyCachingProviderFactory(IEnumerable cachingProviders) - { - this._cachingProviders = cachingProviders; - } - - public IEasyCachingProvider GetCachingProvider(string name) - { - Internal.ArgumentCheck.NotNullOrWhiteSpace(name, nameof(name)); - - var provider = _cachingProviders.FirstOrDefault(x => x.Name.Equals(name, System.StringComparison.OrdinalIgnoreCase)); - - if (provider == null) throw new System.ArgumentException("can not find a match caching provider!"); - - return provider; - } - } -} diff --git a/src/EasyCaching.Core/IEasyCachingPublisher.cs b/src/EasyCaching.Core/IEasyCachingPublisher.cs deleted file mode 100644 index 6b05d88f..00000000 --- a/src/EasyCaching.Core/IEasyCachingPublisher.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace EasyCaching.Core -{ - using System; - using System.Threading.Tasks; - - /// - /// EasyCaching publisher. - /// - public interface IEasyCachingPublisher - { - /// - /// Publish the specified channel and message. - /// - /// The publish. - /// Channel. - /// Message. - /// The 1st type parameter. - void Publish(string channel, EasyCachingMessage message); - - /// - /// Publishs the specified channel and message async. - /// - /// The async. - /// Channel. - /// Message. - /// The 1st type parameter. - Task PublishAsync(string channel, EasyCachingMessage message); - } -} diff --git a/src/EasyCaching.Core/IEasyCachingSubscriber.cs b/src/EasyCaching.Core/IEasyCachingSubscriber.cs deleted file mode 100644 index 018e93d4..00000000 --- a/src/EasyCaching.Core/IEasyCachingSubscriber.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace EasyCaching.Core -{ - using System.Threading.Tasks; - - /// - /// EasyCaching subscriber. - /// - public interface IEasyCachingSubscriber - { - /// - /// Subscribe the specified channel with notifyType. - /// - /// Channel. - void Subscribe(string channel); - - /// - /// Subscribes the specified channel with notifyType async. - /// - /// The async. - /// Channel. - Task SubscribeAsync(string channel); - } -} diff --git a/src/EasyCaching.Core/IHybridCachingProvider.cs b/src/EasyCaching.Core/IHybridCachingProvider.cs index 44d2ff79..71ffc239 100644 --- a/src/EasyCaching.Core/IHybridCachingProvider.cs +++ b/src/EasyCaching.Core/IHybridCachingProvider.cs @@ -1,7 +1,145 @@ namespace EasyCaching.Core { + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + /// /// Hybrid caching provider. /// - public interface IHybridCachingProvider : IEasyCachingProvider { } + public interface IHybridCachingProvider + { + /// + /// Set the specified cacheKey, cacheValue and expiration. + /// + /// Cache key. + /// Cache value. + /// Expiration. + /// The 1st type parameter. + void Set(string cacheKey, T cacheValue, TimeSpan expiration); + + /// + /// Sets the specified cacheKey, cacheValue and expiration async. + /// + /// The async. + /// Cache key. + /// Cache value. + /// Expiration. + /// The 1st type parameter. + Task SetAsync(string cacheKey, T cacheValue, TimeSpan expiration); + + /// + /// Get the specified cacheKey. + /// + /// The get. + /// Cache key. + /// The 1st type parameter. + CacheValue Get(string cacheKey); + + /// + /// Get the specified cacheKey async. + /// + /// The async. + /// Cache key. + /// The 1st type parameter. + Task> GetAsync(string cacheKey); + + /// + /// Remove the specified cacheKey. + /// + /// Cache key. + void Remove(string cacheKey); + + /// + /// Remove the specified cacheKey async. + /// + /// The async. + /// Cache key. + Task RemoveAsync(string cacheKey); + + /// + /// Exists the specified cacheKey async. + /// + /// The async. + /// Cache key. + Task ExistsAsync(string cacheKey); + + /// + /// Exists the specified cacheKey. + /// + /// The exists. + /// Cache key. + bool Exists(string cacheKey); + + /// + /// Tries the set. + /// + /// true, if set was tryed, false otherwise. + /// Cache key. + /// Cache value. + /// Expiration. + /// The 1st type parameter. + bool TrySet(string cacheKey, T cacheValue, TimeSpan expiration); + + /// + /// Tries the set async. + /// + /// The set async. + /// Cache key. + /// Cache value. + /// Expiration. + /// The 1st type parameter. + Task TrySetAsync(string cacheKey, T cacheValue, TimeSpan expiration); + + /// + /// Sets all. + /// + /// Value. + /// Expiration. + /// The 1st type parameter. + void SetAll(IDictionary value, TimeSpan expiration); + + /// + /// Sets all async. + /// + /// The all async. + /// Value. + /// Expiration. + /// The 1st type parameter. + Task SetAllAsync(IDictionary value, TimeSpan expiration); + + /// + /// Removes all. + /// + /// Cache keys. + void RemoveAll(IEnumerable cacheKeys); + + /// + /// Removes all async. + /// + /// The all async. + /// Cache keys. + Task RemoveAllAsync(IEnumerable cacheKeys); + + /// + /// Get the specified cacheKey, dataRetriever and expiration. + /// + /// The get. + /// Cache key. + /// Data retriever. + /// Expiration. + /// The 1st type parameter. + CacheValue Get(string cacheKey, Func dataRetriever, TimeSpan expiration); + + /// + /// Gets the specified cacheKey, dataRetriever and expiration async. + /// + /// The async. + /// Cache key. + /// Data retriever. + /// Expiration. + /// The 1st type parameter. + Task> GetAsync(string cacheKey, Func> dataRetriever, TimeSpan expiration); + + } } diff --git a/src/EasyCaching.Core/IRedisCachingProvider.cs b/src/EasyCaching.Core/IRedisCachingProvider.cs index 494e4adc..8127de68 100644 --- a/src/EasyCaching.Core/IRedisCachingProvider.cs +++ b/src/EasyCaching.Core/IRedisCachingProvider.cs @@ -4,6 +4,12 @@ using System.Collections.Generic; using System.Threading.Tasks; + /// + /// Redis caching provider. + /// + /// + /// Contains some features of redis + /// public interface IRedisCachingProvider : IEasyCachingProvider { #region Hashes diff --git a/src/EasyCaching.Core/DefaultEasyCachingKeyGenerator.cs b/src/EasyCaching.Core/Interceptor/DefaultEasyCachingKeyGenerator.cs similarity index 97% rename from src/EasyCaching.Core/DefaultEasyCachingKeyGenerator.cs rename to src/EasyCaching.Core/Interceptor/DefaultEasyCachingKeyGenerator.cs index 8e4d1762..fb25f656 100644 --- a/src/EasyCaching.Core/DefaultEasyCachingKeyGenerator.cs +++ b/src/EasyCaching.Core/Interceptor/DefaultEasyCachingKeyGenerator.cs @@ -1,11 +1,9 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Interceptor { - using EasyCaching.Core.Internal; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; - using System.Security.Cryptography; using System.Text; /// diff --git a/src/EasyCaching.Core/Internal/EasyCachingInterceptorAttribute.cs b/src/EasyCaching.Core/Interceptor/EasyCachingInterceptorAttribute.cs similarity index 98% rename from src/EasyCaching.Core/Internal/EasyCachingInterceptorAttribute.cs rename to src/EasyCaching.Core/Interceptor/EasyCachingInterceptorAttribute.cs index e660a6b7..80880129 100644 --- a/src/EasyCaching.Core/Internal/EasyCachingInterceptorAttribute.cs +++ b/src/EasyCaching.Core/Interceptor/EasyCachingInterceptorAttribute.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core.Interceptor { using System; diff --git a/src/EasyCaching.Core/Internal/ICachable.cs b/src/EasyCaching.Core/Interceptor/ICachable.cs similarity index 85% rename from src/EasyCaching.Core/Internal/ICachable.cs rename to src/EasyCaching.Core/Interceptor/ICachable.cs index fb71c53e..591587bc 100644 --- a/src/EasyCaching.Core/Internal/ICachable.cs +++ b/src/EasyCaching.Core/Interceptor/ICachable.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core.Interceptor { /// /// Cachable. diff --git a/src/EasyCaching.Core/IEasyCachingKeyGenerator.cs b/src/EasyCaching.Core/Interceptor/IEasyCachingKeyGenerator.cs similarity index 95% rename from src/EasyCaching.Core/IEasyCachingKeyGenerator.cs rename to src/EasyCaching.Core/Interceptor/IEasyCachingKeyGenerator.cs index ed454970..a091333a 100644 --- a/src/EasyCaching.Core/IEasyCachingKeyGenerator.cs +++ b/src/EasyCaching.Core/Interceptor/IEasyCachingKeyGenerator.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Interceptor { using System.Reflection; diff --git a/src/EasyCaching.Core/Internal/ArgumentCheck.cs b/src/EasyCaching.Core/Internal/ArgumentCheck.cs index f7b84ac4..1b6d3000 100644 --- a/src/EasyCaching.Core/Internal/ArgumentCheck.cs +++ b/src/EasyCaching.Core/Internal/ArgumentCheck.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core.Internal +namespace EasyCaching.Core { using System; using System.Collections; diff --git a/src/EasyCaching.Core/CacheValue.cs b/src/EasyCaching.Core/Internal/CacheValue.cs similarity index 100% rename from src/EasyCaching.Core/CacheValue.cs rename to src/EasyCaching.Core/Internal/CacheValue.cs diff --git a/src/EasyCaching.Core/CachingProviderType.cs b/src/EasyCaching.Core/Internal/CachingProviderType.cs similarity index 100% rename from src/EasyCaching.Core/CachingProviderType.cs rename to src/EasyCaching.Core/Internal/CachingProviderType.cs diff --git a/src/EasyCaching.Core/EasyCachingConstValue.cs b/src/EasyCaching.Core/Internal/EasyCachingConstValue.cs similarity index 100% rename from src/EasyCaching.Core/EasyCachingConstValue.cs rename to src/EasyCaching.Core/Internal/EasyCachingConstValue.cs diff --git a/src/EasyCaching.Core/Internal/IEasyCaching.cs b/src/EasyCaching.Core/Internal/IEasyCaching.cs deleted file mode 100644 index f2070ea3..00000000 --- a/src/EasyCaching.Core/Internal/IEasyCaching.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace EasyCaching.Core.Internal -{ - /// - /// Easy caching. - /// - [System.Obsolete("Should Replace with Attribute")] - public interface IEasyCaching - { - } -} diff --git a/src/EasyCaching.Core/Internal/NotifyType.cs b/src/EasyCaching.Core/Internal/NotifyType.cs deleted file mode 100644 index 8eb65d45..00000000 --- a/src/EasyCaching.Core/Internal/NotifyType.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace EasyCaching.Core.Internal -{ - /// - /// Notify type. - /// - public enum NotifyType - { - Add = 0, - Update = 1, - Delete = 2 - } -} diff --git a/src/EasyCaching.Core/ProviderFactory/DefaultEasyCachingProviderFactory.cs b/src/EasyCaching.Core/ProviderFactory/DefaultEasyCachingProviderFactory.cs new file mode 100644 index 00000000..c0341e41 --- /dev/null +++ b/src/EasyCaching.Core/ProviderFactory/DefaultEasyCachingProviderFactory.cs @@ -0,0 +1,42 @@ +namespace EasyCaching.Core +{ + using System; + using System.Collections.Generic; + using System.Linq; + + /// + /// Default easycaching provider factory. + /// + public class DefaultEasyCachingProviderFactory : IEasyCachingProviderFactory + { + /// + /// The caching providers. + /// + private readonly IEnumerable _cachingProviders; + + /// + /// Initializes a new instance of the class. + /// + /// Caching providers. + public DefaultEasyCachingProviderFactory(IEnumerable cachingProviders) + { + this._cachingProviders = cachingProviders; + } + + /// + /// Gets the caching provider. + /// + /// The caching provider. + /// Name. + public IEasyCachingProvider GetCachingProvider(string name) + { + ArgumentCheck.NotNullOrWhiteSpace(name, nameof(name)); + + var provider = _cachingProviders.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); + + if (provider == null) throw new ArgumentException("can not find a match caching provider!"); + + return provider; + } + } +} diff --git a/src/EasyCaching.Core/ProviderFactory/IEasyCachingProviderFactory.cs b/src/EasyCaching.Core/ProviderFactory/IEasyCachingProviderFactory.cs new file mode 100644 index 00000000..748e4c4d --- /dev/null +++ b/src/EasyCaching.Core/ProviderFactory/IEasyCachingProviderFactory.cs @@ -0,0 +1,15 @@ +namespace EasyCaching.Core +{ + /// + /// EasyCaching provider factory. + /// + public interface IEasyCachingProviderFactory + { + /// + /// Gets the caching provider. + /// + /// The caching provider. + /// Name. + IEasyCachingProvider GetCachingProvider(string name); + } +} diff --git a/src/EasyCaching.Core/DefaultBinaryFormatterSerializer.cs b/src/EasyCaching.Core/Serialization/DefaultBinaryFormatterSerializer.cs similarity index 97% rename from src/EasyCaching.Core/DefaultBinaryFormatterSerializer.cs rename to src/EasyCaching.Core/Serialization/DefaultBinaryFormatterSerializer.cs index 7dd39e6f..1cc5752e 100644 --- a/src/EasyCaching.Core/DefaultBinaryFormatterSerializer.cs +++ b/src/EasyCaching.Core/Serialization/DefaultBinaryFormatterSerializer.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Serialization { using System; using System.IO; diff --git a/src/EasyCaching.Core/IEasyCachingSerializer.cs b/src/EasyCaching.Core/Serialization/IEasyCachingSerializer.cs similarity index 96% rename from src/EasyCaching.Core/IEasyCachingSerializer.cs rename to src/EasyCaching.Core/Serialization/IEasyCachingSerializer.cs index b68bc4e0..12ccc71c 100644 --- a/src/EasyCaching.Core/IEasyCachingSerializer.cs +++ b/src/EasyCaching.Core/Serialization/IEasyCachingSerializer.cs @@ -1,4 +1,4 @@ -namespace EasyCaching.Core +namespace EasyCaching.Core.Serialization { using System; diff --git a/src/EasyCaching.Core/CacheStatsCounter.cs b/src/EasyCaching.Core/Stats/CacheStats.cs similarity index 61% rename from src/EasyCaching.Core/CacheStatsCounter.cs rename to src/EasyCaching.Core/Stats/CacheStats.cs index 94fac245..7938d4aa 100644 --- a/src/EasyCaching.Core/CacheStatsCounter.cs +++ b/src/EasyCaching.Core/Stats/CacheStats.cs @@ -1,60 +1,60 @@ namespace EasyCaching.Core { using System.Collections.Concurrent; - using System.Threading; /// - /// Cache stats counter. + /// Cache stats. /// - public class CacheStatsCounter - { - private long[] _counters = new long[2]; - - public void Increment(StatsType statsType) - { - Interlocked.Increment(ref _counters[(int)statsType]); - } - - public long Get(StatsType statsType) - { - return Interlocked.Read(ref _counters[(int)statsType]); - } - } - - public enum StatsType - { - Hit = 0, - - Missed = 1, - } - public class CacheStats { + /// + /// The counters. + /// private readonly ConcurrentDictionary _counters; + /// + /// The default key. + /// private const string DEFAULT_KEY = "easycahing_catche_stats"; - + /// + /// Initializes a new instance of the class. + /// public CacheStats() { _counters = new ConcurrentDictionary(); } + /// + /// Ons the hit. + /// public void OnHit() { GetCounter().Increment(StatsType.Hit); } + /// + /// Ons the miss. + /// public void OnMiss() { GetCounter().Increment(StatsType.Missed); } + /// + /// Gets the statistic. + /// + /// The statistic. + /// Stats type. public long GetStatistic(StatsType statsType) { return GetCounter().Get(statsType); } + /// + /// Gets the counter. + /// + /// The counter. private CacheStatsCounter GetCounter() { if (!_counters.TryGetValue(DEFAULT_KEY, out CacheStatsCounter counter)) diff --git a/src/EasyCaching.Core/Stats/CacheStatsCounter.cs b/src/EasyCaching.Core/Stats/CacheStatsCounter.cs new file mode 100644 index 00000000..b2e5a8e5 --- /dev/null +++ b/src/EasyCaching.Core/Stats/CacheStatsCounter.cs @@ -0,0 +1,34 @@ +namespace EasyCaching.Core +{ + using System.Threading; + + /// + /// Cache stats counter. + /// + public class CacheStatsCounter + { + /// + /// The counters. + /// + private long[] _counters = new long[2]; + + /// + /// Increment the specified statsType. + /// + /// Stats type. + public void Increment(StatsType statsType) + { + Interlocked.Increment(ref _counters[(int)statsType]); + } + + /// + /// Get the specified statsType. + /// + /// The get. + /// Stats type. + public long Get(StatsType statsType) + { + return Interlocked.Read(ref _counters[(int)statsType]); + } + } +} diff --git a/src/EasyCaching.Core/Stats/StatsType.cs b/src/EasyCaching.Core/Stats/StatsType.cs new file mode 100644 index 00000000..56f1ad5a --- /dev/null +++ b/src/EasyCaching.Core/Stats/StatsType.cs @@ -0,0 +1,18 @@ +namespace EasyCaching.Core +{ + /// + /// Stats type. + /// + public enum StatsType + { + /// + /// The hit. + /// + Hit = 0, + + /// + /// The missed. + /// + Missed = 1, + } +} diff --git a/src/EasyCaching.HybridCache/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.HybridCache/Configurations/EasyCachingOptionsExtensions.cs index d66a64ed..c8f8c992 100644 --- a/src/EasyCaching.HybridCache/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.HybridCache/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.HybridCache { - using EasyCaching.Core; + using System; + using EasyCaching.Core.Configurations; /// /// EasyCaching options extensions. @@ -12,9 +13,9 @@ public static class EasyCachingOptionsExtensions /// /// The hybrid. /// Options. - public static EasyCachingOptions UseHybrid(this EasyCachingOptions options) + public static EasyCachingOptions UseHybrid(this EasyCachingOptions options, Action configure) { - options.RegisterExtension(new HybridCacheOptionsExtension()); + options.RegisterExtension(new HybridCacheOptionsExtension(configure)); return options; } diff --git a/src/EasyCaching.HybridCache/Configurations/HybridCacheOptionsExtension.cs b/src/EasyCaching.HybridCache/Configurations/HybridCacheOptionsExtension.cs index cfb10801..9cc890ff 100644 --- a/src/EasyCaching.HybridCache/Configurations/HybridCacheOptionsExtension.cs +++ b/src/EasyCaching.HybridCache/Configurations/HybridCacheOptionsExtension.cs @@ -1,6 +1,8 @@ namespace EasyCaching.HybridCache { + using System; using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -10,12 +12,24 @@ /// internal sealed class HybridCacheOptionsExtension : IEasyCachingOptionsExtension { + /// + /// The configure. + /// + private readonly Action _configure; + + public HybridCacheOptionsExtension( Action configure) + { + this._configure = configure; + } + /// /// Adds the services. /// /// Services. public void AddServices(IServiceCollection services) { + services.AddOptions(); + services.Configure(_configure); services.TryAddSingleton(); } diff --git a/src/EasyCaching.HybridCache/Configurations/HybridCachingOptions.cs b/src/EasyCaching.HybridCache/Configurations/HybridCachingOptions.cs new file mode 100644 index 00000000..a77f4845 --- /dev/null +++ b/src/EasyCaching.HybridCache/Configurations/HybridCachingOptions.cs @@ -0,0 +1,18 @@ +namespace EasyCaching.HybridCache +{ + public class HybridCachingOptions + { + /// + /// Gets or sets the name of the topic. + /// + /// The name of the topic. + public string TopicName { get; set; } + + /// + /// Gets or sets a value indicating whether this + /// enable logging. + /// + /// true if enable logging; otherwise, false. + public bool EnableLogging { get; set; } + } +} diff --git a/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj b/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj index 3eef1a2d..547d5ec5 100644 --- a/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj +++ b/src/EasyCaching.HybridCache/EasyCaching.HybridCache.csproj @@ -7,9 +7,9 @@ Catcher Wong $(EasyCachingHybridPackageVersion) - EasyCaching.HybridCache combines local caching and distributed caching. + A simple hybrid caching provider combines local caching and distributed caching. - Caching,Cache,Synchronization,Hybrid + Hybrid,Synchronization,LocalCache,DistributedCache,Caching https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching @@ -25,6 +25,7 @@ + diff --git a/src/EasyCaching.HybridCache/HybridCacheServiceCollectionExtensions.cs b/src/EasyCaching.HybridCache/HybridCacheServiceCollectionExtensions.cs index b6ac9599..a0eb1e4b 100644 --- a/src/EasyCaching.HybridCache/HybridCacheServiceCollectionExtensions.cs +++ b/src/EasyCaching.HybridCache/HybridCacheServiceCollectionExtensions.cs @@ -1,10 +1,9 @@ namespace EasyCaching.HybridCache { using EasyCaching.Core; - using EasyCaching.Core.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; - + /// /// Hybrid cache service collection extensions. /// diff --git a/src/EasyCaching.HybridCache/HybridCachingProvider.cs b/src/EasyCaching.HybridCache/HybridCachingProvider.cs index 84e59a22..62ea2b7e 100644 --- a/src/EasyCaching.HybridCache/HybridCachingProvider.cs +++ b/src/EasyCaching.HybridCache/HybridCachingProvider.cs @@ -1,11 +1,13 @@ namespace EasyCaching.HybridCache { - using EasyCaching.Core; - using EasyCaching.Core.Internal; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; + using EasyCaching.Core; + using EasyCaching.Core.Bus; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; /// /// Hybrid caching provider. @@ -13,60 +15,89 @@ public class HybridCachingProvider : IHybridCachingProvider { /// - /// The caching providers. + /// The local cache. /// - private readonly IEnumerable _providers; - + private readonly IEasyCachingProvider _localCache; /// - /// Gets a value indicating whether this is - /// distributed cache. + /// The distributed cache. /// - /// true if is distributed cache; otherwise, false. - public bool IsDistributedCache => throw new NotImplementedException(); - + private readonly IEasyCachingProvider _distributedCache; /// - /// Gets the order. + /// The bus. /// - /// The order. - public int Order => throw new NotImplementedException(); - + private readonly IEasyCachingBus _bus; + /// + /// The options. + /// + private readonly HybridCachingOptions _options; + /// + /// The logger. + /// + private readonly ILogger _logger; /// - /// Gets the max rd second. + /// The cache identifier. /// - /// The max rd second. - public int MaxRdSecond => throw new NotImplementedException(); + private readonly string _cacheId; /// - /// Gets the type of the caching provider. + /// Initializes a new instance of the class. /// - /// The type of the caching provider. - public CachingProviderType CachingProviderType => throw new NotImplementedException(); + /// Options accs. + /// Providers. + /// Bus. + /// Logger factory. + public HybridCachingProvider( + IOptions optionsAccs + , IEnumerable providers + , IEasyCachingBus bus = null + , ILoggerFactory loggerFactory = null + ) + { + ArgumentCheck.NotNullAndCountGTZero(providers, nameof(providers)); + + this._options = optionsAccs.Value; + + ArgumentCheck.NotNullOrWhiteSpace(_options.TopicName, nameof(_options.TopicName)); + + this._logger = loggerFactory?.CreateLogger(); + + //Here use the order to distinguish traditional provider + var local = providers.OrderBy(x => x.Order).FirstOrDefault(x => !x.IsDistributedCache); - public CacheStats CacheStats => throw new NotImplementedException(); + if (local == null) throw new NotFoundCachingProviderException("Can not found any local caching providers."); + else this._localCache = local; - public string Name => throw new NotImplementedException(); + //Here use the order to distinguish traditional provider + var distributed = providers.OrderBy(x => x.Order).FirstOrDefault(x => x.IsDistributedCache); + + if (distributed == null) throw new NotFoundCachingProviderException("Can not found any distributed caching providers."); + else this._distributedCache = distributed; + + this._bus = bus ?? NullEasyCachingBus.Instance; + this._bus.Subscribe(_options.TopicName, OnMessage); + + this._cacheId = Guid.NewGuid().ToString("N"); + } /// - /// Initializes a new instance of the class. + /// Ons the message. /// - /// Providers. - public HybridCachingProvider(IEnumerable providers) + /// Message. + private void OnMessage(EasyCachingMessage message) { - if (providers == null || !providers.Any()) - { - throw new ArgumentNullException(nameof(providers)); - } + // each clients will recive the message, current client should ignore. + if (!string.IsNullOrWhiteSpace(message.Id) && message.Id.Equals(_cacheId, StringComparison.OrdinalIgnoreCase)) + return; - //2-level and 3-level are enough for hybrid - if (providers.Count() > 3) + foreach (var item in message.CacheKeys) { - throw new ArgumentOutOfRangeException(nameof(providers)); - } - - // - this._providers = providers.OrderBy(x => x.Order); + _localCache.Remove(item); - //TODO: local cache should subscribe the remote cache + if (_options.EnableLogging) + { + _logger.LogTrace($"remove local cache that cache key is {item}"); + } + } } /// @@ -78,16 +109,7 @@ public bool Exists(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - var flag = false; - - foreach (var provider in _providers) - { - flag = provider.Exists(cacheKey); - - if (flag) break; - } - - return flag; + return _distributedCache.Exists(cacheKey); } /// @@ -99,176 +121,103 @@ public async Task ExistsAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - var flag = false; - - foreach (var provider in _providers) - { - flag = provider.Exists(cacheKey); - - if (flag) break; - } - - return await Task.FromResult(flag); + return await _distributedCache.ExistsAsync(cacheKey); } /// - /// Get the specified cacheKey, dataRetriever and expiration. + /// Get the specified cacheKey. /// /// The get. /// Cache key. - /// Data retriever. - /// Expiration. /// The 1st type parameter. - public CacheValue Get(string cacheKey, Func dataRetriever, TimeSpan expiration) + public CacheValue Get(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - CacheValue cachedValue = null; - - foreach (var provider in _providers) - { - cachedValue = provider.Get(cacheKey, dataRetriever, expiration); + var cacheValue = _localCache.Get(cacheKey); - if (cachedValue.HasValue) - { - break; - } + if (cacheValue.HasValue) + { + return cacheValue; } - if (!cachedValue.HasValue) + if (_options.EnableLogging) { - var retriever = dataRetriever(); - if (retriever != null) - { - Set(cacheKey, retriever, expiration); - return new CacheValue(retriever, true); - } - else - { - //TODO : Set a null value to cache!! - return CacheValue.NoValue; - } + _logger.LogTrace($"local cache can not get the value of {cacheKey}"); } - return cachedValue; - } - - /// - /// Get the specified cacheKey. - /// - /// The get. - /// Cache key. - /// The 1st type parameter. - public CacheValue Get(string cacheKey) - { - ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + cacheValue = _distributedCache.Get(cacheKey); - CacheValue cachedValue = null; - - foreach (var provider in _providers) + if (cacheValue.HasValue) { - cachedValue = provider.Get(cacheKey); + //TODO: What about the value of expiration? Form configuration or others? + _localCache.Set(cacheKey, cacheValue.Value, TimeSpan.FromSeconds(60)); - if (cachedValue.HasValue) - { - break; - } + return cacheValue; } - if (!cachedValue.HasValue) + if (_options.EnableLogging) { - return CacheValue.NoValue; + _logger.LogTrace($"distributed cache can not get the value of {cacheKey}"); } - return cachedValue; + return CacheValue.NoValue; } /// - /// Gets the specified cacheKey, dataRetriever and expiration async. + /// Gets the specified cacheKey async. /// /// The async. /// Cache key. - /// Data retriever. - /// Expiration. /// The 1st type parameter. - public async Task> GetAsync(string cacheKey, Func> dataRetriever, TimeSpan expiration) + public async Task> GetAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - CacheValue cachedValue = null; + var cacheValue = await _localCache.GetAsync(cacheKey); - foreach (var provider in _providers) + if (cacheValue.HasValue) { - cachedValue = provider.Get(cacheKey); - - if (cachedValue.HasValue) - { - break; - } + return cacheValue; } - if (!cachedValue.HasValue) + if (_options.EnableLogging) { - var retriever = await dataRetriever?.Invoke(); - if (retriever != null) - { - await SetAsync(cacheKey, retriever, expiration); - return new CacheValue(retriever, true); - } - else - { - return CacheValue.NoValue; - } + _logger.LogTrace($"local cache can not get the value of {cacheKey}"); } - return cachedValue; - } + cacheValue = await _distributedCache.GetAsync(cacheKey); - /// - /// Gets the specified cacheKey async. - /// - /// The async. - /// Cache key. - /// The 1st type parameter. - public async Task> GetAsync(string cacheKey) - { - ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - - CacheValue cachedValue = null; - - foreach (var provider in _providers) + if (cacheValue.HasValue) { - cachedValue = provider.Get(cacheKey); + //TODO: What about the value of expiration? Form configuration or others? + await _localCache.SetAsync(cacheKey, cacheValue.Value, TimeSpan.FromSeconds(60)); - if (cachedValue.HasValue) - { - break; - } + return cacheValue; } - if (!cachedValue.HasValue) + if (_options.EnableLogging) { - return CacheValue.NoValue; + _logger.LogTrace($"distributed cache can not get the value of {cacheKey}"); } - return await Task.FromResult(cachedValue); + return CacheValue.NoValue; } /// /// Remove the specified cacheKey. /// - /// The remove. /// Cache key. public void Remove(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - foreach (var provider in _providers) - { - provider.Remove(cacheKey); - } + //distributed cache at first + _distributedCache.Remove(cacheKey); + _localCache.Remove(cacheKey); + + //send message to bus + _bus.Publish(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } }); } /// @@ -280,20 +229,17 @@ public async Task RemoveAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - var tasks = new List(); + //distributed cache at first + await _distributedCache.RemoveAsync(cacheKey); + await _localCache.RemoveAsync(cacheKey); - foreach (var provider in _providers) - { - tasks.Add(provider.RemoveAsync(cacheKey)); - } - - await Task.WhenAll(tasks); + //send message to bus + await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } }); } /// /// Set the specified cacheKey, cacheValue and expiration. /// - /// The set. /// Cache key. /// Cache value. /// Expiration. @@ -301,13 +247,12 @@ public async Task RemoveAsync(string cacheKey) public void Set(string cacheKey, T cacheValue, TimeSpan expiration) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - ArgumentCheck.NotNull(cacheValue, nameof(cacheValue)); - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - foreach (var provider in _providers) - { - provider.Set(cacheKey, cacheValue, expiration); - } + _localCache.Set(cacheKey, cacheValue, expiration); + _distributedCache.Set(cacheKey, cacheValue, expiration); + + //When create/update cache, send message to bus so that other clients can remove it. + _bus.Publish(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } }); } /// @@ -321,352 +266,168 @@ public void Set(string cacheKey, T cacheValue, TimeSpan expiration) public async Task SetAsync(string cacheKey, T cacheValue, TimeSpan expiration) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - ArgumentCheck.NotNull(cacheValue, nameof(cacheValue)); - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - var tasks = new List(); + await _localCache.SetAsync(cacheKey, cacheValue, expiration); + await _distributedCache.SetAsync(cacheKey, cacheValue, expiration); - foreach (var provider in _providers) - { - tasks.Add(provider.SetAsync(cacheKey, cacheValue, expiration)); - } - - await Task.WhenAll(tasks); + //When create/update cache, send message to bus so that other clients can remove it. + await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = new string[] { cacheKey } }); } /// - /// Refresh the specified cacheKey, cacheValue and expiration. + /// Tries the set. /// + /// true, if set was tryed, false otherwise. /// Cache key. /// Cache value. /// Expiration. /// The 1st type parameter. - public void Refresh(string cacheKey, T cacheValue, TimeSpan expiration) + public bool TrySet(string cacheKey, T cacheValue, TimeSpan expiration) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - ArgumentCheck.NotNull(cacheValue, nameof(cacheValue)); - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - this.Remove(cacheKey); - this.Set(cacheKey, cacheValue, expiration); + var flag = _distributedCache.TrySet(cacheKey, cacheValue, expiration); + + if (flag) + { + //When TrySet succeed in distributed cache, Set(not TrySet) this cache to local cache. + _localCache.Set(cacheKey, cacheValue, expiration); + } + + return flag; } /// - /// Refreshs the specified cacheKey, cacheValue and expiration. + /// Tries the set async. /// - /// The async. + /// The set async. /// Cache key. /// Cache value. /// Expiration. /// The 1st type parameter. - public async Task RefreshAsync(string cacheKey, T cacheValue, TimeSpan expiration) + public async Task TrySetAsync(string cacheKey, T cacheValue, TimeSpan expiration) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); - ArgumentCheck.NotNull(cacheValue, nameof(cacheValue)); - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - - await this.RemoveAsync(cacheKey); - await this.SetAsync(cacheKey, cacheValue, expiration); - } - - /// - /// Removes cached item by cachekey's prefix. - /// - /// The by prefix async. - /// Prefix. - public void RemoveByPrefix(string prefix) - { - ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix)); - - foreach (var provider in _providers) - { - provider.RemoveByPrefix(prefix); - } - } - - /// - /// Removes cached item by cachekey's prefix async. - /// - /// The by prefix async. - /// Prefix. - public async Task RemoveByPrefixAsync(string prefix) - { - ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix)); - var tasks = new List(); + var flag = await _distributedCache.TrySetAsync(cacheKey, cacheValue, expiration); - foreach (var provider in _providers) + if (flag) { - tasks.Add(provider.RemoveByPrefixAsync(prefix)); + //When we TrySet succeed in distributed cache, we should Set this cache to local cache. + await _localCache.SetAsync(cacheKey, cacheValue, expiration); } - await Task.WhenAll(tasks); + return flag; } /// /// Sets all. /// - /// Values. + /// Value. /// Expiration. /// The 1st type parameter. - public void SetAll(IDictionary values, TimeSpan expiration) + public void SetAll(IDictionary value, TimeSpan expiration) { - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - ArgumentCheck.NotNullAndCountGTZero(values, nameof(values)); - - foreach (var provider in _providers) - { - provider.SetAll(values, expiration); - } + _distributedCache.SetAll(value, expiration); } /// /// Sets all async. /// /// The all async. - /// Values. + /// Value. /// Expiration. /// The 1st type parameter. - public async Task SetAllAsync(IDictionary values, TimeSpan expiration) + public async Task SetAllAsync(IDictionary value, TimeSpan expiration) { - ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - ArgumentCheck.NotNullAndCountGTZero(values, nameof(values)); - - var tasks = new List(); - - foreach (var provider in _providers) - { - tasks.Add(provider.SetAllAsync(values, expiration)); - } - - await Task.WhenAll(tasks); + await _distributedCache.SetAllAsync(value, expiration); } /// - /// Gets all. + /// Removes all. /// - /// The all. /// Cache keys. - /// The 1st type parameter. - public IDictionary> GetAll(IEnumerable cacheKeys) + public void RemoveAll(IEnumerable cacheKeys) { ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); - var local = _providers.FirstOrDefault(); + _localCache.RemoveAll(cacheKeys); - var localDict = local.GetAll(cacheKeys); - - //not find in local caching. - var localNotFindKeys = localDict.Where(x => !x.Value.HasValue).Select(x => x.Key); - - if (!localNotFindKeys.Any()) - { - return localDict; - } + _distributedCache.RemoveAllAsync(cacheKeys); - foreach (var item in localNotFindKeys) - localDict.Remove(item); - - //remote - foreach (var provider in _providers.Skip(1)) - { - var disDict = provider.GetAll(localNotFindKeys); - localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); - } - - return localDict; + //send message to bus in order to notify other clients. + _bus.Publish(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = cacheKeys.ToArray() }); } /// - /// Gets all async. + /// Removes all async. /// /// The all async. /// Cache keys. - /// The 1st type parameter. - public async Task>> GetAllAsync(IEnumerable cacheKeys) + public async Task RemoveAllAsync(IEnumerable cacheKeys) { ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); - var local = _providers.FirstOrDefault(); + await _localCache.RemoveAllAsync(cacheKeys); - var localDict = await local.GetAllAsync(cacheKeys); + await _distributedCache.RemoveAllAsync(cacheKeys); - //not find in local caching. - var localNotFindKeys = localDict.Where(x => !x.Value.HasValue).Select(x => x.Key); - - if (!localNotFindKeys.Any()) - { - return localDict; - } - - foreach (var item in localNotFindKeys) - localDict.Remove(item); - - //remote - foreach (var provider in _providers.Skip(1)) - { - var disDict = provider.GetAll(localNotFindKeys); - localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); - } - - return localDict; + //send message to bus in order to notify other clients. + await _bus.PublishAsync(_options.TopicName, new EasyCachingMessage { Id = _cacheId, CacheKeys = cacheKeys.ToArray() }); } /// - /// Gets the by prefix. + /// Get the specified cacheKey, dataRetriever and expiration. /// - /// The by prefix. - /// Prefix. + /// The get. + /// Cache key. + /// Data retriever. + /// Expiration. /// The 1st type parameter. - public IDictionary> GetByPrefix(string prefix) + public CacheValue Get(string cacheKey, Func dataRetriever, TimeSpan expiration) { - ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix)); - - var local = _providers.FirstOrDefault(); - - var localDict = local.GetByPrefix(prefix); + ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - //not find in local caching. - var localNotFindKeys = localDict.Where(x => !x.Value.HasValue).Select(x => x.Key); + var result = _localCache.Get(cacheKey); - if (!localNotFindKeys.Any()) + if(result.HasValue) { - return localDict; + return result; } - foreach (var item in localNotFindKeys) - localDict.Remove(item); - - //remote - foreach (var provider in _providers.Skip(1)) - { - var disDict = provider.GetAll(localNotFindKeys); - localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); - } + result = _distributedCache.Get(cacheKey, dataRetriever , expiration); - return localDict; + return result.HasValue + ? result + : CacheValue.NoValue; } /// - /// Gets the by prefix async. + /// Gets the specified cacheKey, dataRetriever and expiration async. /// - /// The by prefix async. - /// Prefix. + /// The async. + /// Cache key. + /// Data retriever. + /// Expiration. /// The 1st type parameter. - public async Task>> GetByPrefixAsync(string prefix) - { - ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix)); - - var local = _providers.FirstOrDefault(); - - var localDict = await local.GetByPrefixAsync(prefix); - - //not find in local caching. - var localNotFindKeys = localDict.Where(x => !x.Value.HasValue).Select(x => x.Key); - - if (!localNotFindKeys.Any()) - { - return localDict; - } - - foreach (var item in localNotFindKeys) - localDict.Remove(item); - - //remote - foreach (var provider in _providers.Skip(1)) - { - var disDict = provider.GetAll(localNotFindKeys); - localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value); - } - - return localDict; - } - - /// - /// Removes all. - /// - /// Cache keys. - public void RemoveAll(IEnumerable cacheKeys) - { - ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); - - foreach (var provider in _providers) - { - provider.RemoveAll(cacheKeys); - } - } - - /// - /// Removes all async. - /// - /// The all async. - /// Cache keys. - public async Task RemoveAllAsync(IEnumerable cacheKeys) - { - ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); - - var tasks = new List(); - - foreach (var provider in _providers) - { - tasks.Add(provider.RemoveAllAsync(cacheKeys)); - } - - await Task.WhenAll(tasks); - } - - /// - /// Gets the count. - /// - /// The count. - /// Prefix. - public int GetCount(string prefix = "") - { - var list = new List(); - - foreach (var provider in _providers) - { - list.Add(provider.GetCount(prefix)); - } - - return list.OrderByDescending(x => x).FirstOrDefault(); - } - - /// - /// Flush All Cached Item. - /// - public void Flush() + public async Task> GetAsync(string cacheKey, Func> dataRetriever, TimeSpan expiration) { - foreach (var provider in _providers) - { - provider.Flush(); - } - } + ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); + ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration)); - /// - /// Flush All Cached Item async. - /// - /// The async. - public async Task FlushAsync() - { - var tasks = new List(); + var result = await _localCache.GetAsync(cacheKey); - foreach (var provider in _providers) + if (result.HasValue) { - tasks.Add(provider.FlushAsync()); + return result; } - await Task.WhenAll(tasks); - } + result = await _distributedCache.GetAsync(cacheKey, dataRetriever , expiration); - public bool TrySet(string cacheKey, T cacheValue, TimeSpan expiration) - { - throw new NotImplementedException(); - } - - public Task TrySetAsync(string cacheKey, T cacheValue, TimeSpan expiration) - { - throw new NotImplementedException(); + return result.HasValue + ? result + : CacheValue.NoValue; } } } diff --git a/src/EasyCaching.HybridCache/NotFoundCachingProviderException.cs b/src/EasyCaching.HybridCache/NotFoundCachingProviderException.cs new file mode 100644 index 00000000..4bc39db4 --- /dev/null +++ b/src/EasyCaching.HybridCache/NotFoundCachingProviderException.cs @@ -0,0 +1,10 @@ +namespace EasyCaching.HybridCache +{ + using System; + + public class NotFoundCachingProviderException : Exception + { + public NotFoundCachingProviderException(string message) : base(message) + { } + } +} diff --git a/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs index 75bcb05c..e6930099 100644 --- a/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.InMemory/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.InMemory { using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; using System; diff --git a/src/EasyCaching.InMemory/Configurations/InMemoryOptions.cs b/src/EasyCaching.InMemory/Configurations/InMemoryOptions.cs index 9f92d6fb..b7c7a4ea 100644 --- a/src/EasyCaching.InMemory/Configurations/InMemoryOptions.cs +++ b/src/EasyCaching.InMemory/Configurations/InMemoryOptions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.InMemory { using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; public class InMemoryOptions : BaseProviderOptions { diff --git a/src/EasyCaching.InMemory/Configurations/InMemoryOptionsExtension.cs b/src/EasyCaching.InMemory/Configurations/InMemoryOptionsExtension.cs index 89b0949c..bfba4dc0 100644 --- a/src/EasyCaching.InMemory/Configurations/InMemoryOptionsExtension.cs +++ b/src/EasyCaching.InMemory/Configurations/InMemoryOptionsExtension.cs @@ -1,6 +1,7 @@ namespace EasyCaching.InMemory { using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj b/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj index 97157293..68b81006 100644 --- a/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj +++ b/src/EasyCaching.InMemory/EasyCaching.InMemory.csproj @@ -6,10 +6,10 @@ Catcher Wong Catcher Wong $(EasyCachingInMemoryPackageVersion) - - In-memory cache based on EasyCaching.Core and Microsoft.Extensions.Caching.Memory + + A simple in-memory caching provider. - Caching,Cache,In-Memory + In-Memory,LocalCache,Caching,Cache https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Interceptor.AspectCore/AspectCoreInterceptorServiceCollectionExtensions.cs b/src/EasyCaching.Interceptor.AspectCore/AspectCoreInterceptorServiceCollectionExtensions.cs index 971be74b..e62a0194 100644 --- a/src/EasyCaching.Interceptor.AspectCore/AspectCoreInterceptorServiceCollectionExtensions.cs +++ b/src/EasyCaching.Interceptor.AspectCore/AspectCoreInterceptorServiceCollectionExtensions.cs @@ -10,6 +10,7 @@ using System; using System.Linq; using System.Reflection; + using EasyCaching.Core.Interceptor; /// /// Aspectcore interceptor service collection extensions. diff --git a/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj b/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj index e27e6853..67c67eba 100644 --- a/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj +++ b/src/EasyCaching.Interceptor.AspectCore/EasyCaching.Interceptor.AspectCore.csproj @@ -6,10 +6,10 @@ Catcher Wong Catcher Wong $(EasyCachingAspectCorePackageVersion) - - Caching Interceptor based on EasyCaching.Core and AspectCore + + A simple caching AOP extension library based on AspectCore - Caching,Cache,Distributed,Memory,Interceptor,Synchronization + Interceptor,AspectCore,AOP,Caching,Cache https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Interceptor.AspectCore/EasyCachingInterceptor.cs b/src/EasyCaching.Interceptor.AspectCore/EasyCachingInterceptor.cs index 5219ec55..3d7b11c5 100644 --- a/src/EasyCaching.Interceptor.AspectCore/EasyCachingInterceptor.cs +++ b/src/EasyCaching.Interceptor.AspectCore/EasyCachingInterceptor.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Threading.Tasks; using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Interceptor; using global::AspectCore.DynamicProxy; using global::AspectCore.Injector; diff --git a/src/EasyCaching.Interceptor.Castle/CastleInterceptorServiceCollectionExtensions.cs b/src/EasyCaching.Interceptor.Castle/CastleInterceptorServiceCollectionExtensions.cs index a0ce85c5..f6a43925 100644 --- a/src/EasyCaching.Interceptor.Castle/CastleInterceptorServiceCollectionExtensions.cs +++ b/src/EasyCaching.Interceptor.Castle/CastleInterceptorServiceCollectionExtensions.cs @@ -1,15 +1,14 @@ namespace EasyCaching.Interceptor.Castle { + using System; + using System.Linq; + using System.Reflection; using Autofac; using Autofac.Extensions.DependencyInjection; using Autofac.Extras.DynamicProxy; - using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Interceptor; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; - using System; - using System.Linq; - using System.Reflection; /// /// Castle interceptor service collection extensions. diff --git a/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj b/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj index e1f068e2..3b1b0d85 100644 --- a/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj +++ b/src/EasyCaching.Interceptor.Castle/EasyCaching.Interceptor.Castle.csproj @@ -7,9 +7,9 @@ Catcher Wong $(EasyCachingCastlePackageVersion) - Caching Interceptor based on EasyCaching.Core and Castle + A simple caching AOP extension library based on Castle - Caching,Cache,Distributed,Memory,Interceptor,Synchronization + Interceptor,Castle,AOP,Caching,Cache https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Interceptor.Castle/EasyCachingInterceptor.cs b/src/EasyCaching.Interceptor.Castle/EasyCachingInterceptor.cs index 2a5db4ea..f61a52de 100644 --- a/src/EasyCaching.Interceptor.Castle/EasyCachingInterceptor.cs +++ b/src/EasyCaching.Interceptor.Castle/EasyCachingInterceptor.cs @@ -1,10 +1,10 @@ namespace EasyCaching.Interceptor.Castle { - using EasyCaching.Core; - using EasyCaching.Core.Internal; - using global::Castle.DynamicProxy; using System; using System.Linq; + using EasyCaching.Core; + using EasyCaching.Core.Interceptor; + using global::Castle.DynamicProxy; /// /// Easycaching interceptor. diff --git a/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs index 075da45b..eaee4b59 100644 --- a/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Memcached/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Memcached { using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; using System; diff --git a/src/EasyCaching.Memcached/Configurations/EasyCachingTranscoder.cs b/src/EasyCaching.Memcached/Configurations/EasyCachingTranscoder.cs index 5fab70f1..74d5a54c 100755 --- a/src/EasyCaching.Memcached/Configurations/EasyCachingTranscoder.cs +++ b/src/EasyCaching.Memcached/Configurations/EasyCachingTranscoder.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Memcached { - using EasyCaching.Core; + using EasyCaching.Core; + using EasyCaching.Core.Serialization; using Enyim.Caching.Memcached; using System; diff --git a/src/EasyCaching.Memcached/Configurations/MemcachedOptions.cs b/src/EasyCaching.Memcached/Configurations/MemcachedOptions.cs index d4160bca..53d032ed 100644 --- a/src/EasyCaching.Memcached/Configurations/MemcachedOptions.cs +++ b/src/EasyCaching.Memcached/Configurations/MemcachedOptions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.Memcached { using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; public class MemcachedOptions : BaseProviderOptions { diff --git a/src/EasyCaching.Memcached/Configurations/MemcachedOptionsExtension.cs b/src/EasyCaching.Memcached/Configurations/MemcachedOptionsExtension.cs index 0e7d2b5b..9fa42f23 100644 --- a/src/EasyCaching.Memcached/Configurations/MemcachedOptionsExtension.cs +++ b/src/EasyCaching.Memcached/Configurations/MemcachedOptionsExtension.cs @@ -1,6 +1,10 @@ namespace EasyCaching.Memcached { + using System; + using System.Linq; using EasyCaching.Core; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; using Enyim.Caching; using Enyim.Caching.Configuration; using Enyim.Caching.Memcached; @@ -9,8 +13,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; - using System; - using System.Linq; /// /// Memcached options extension. diff --git a/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj b/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj index c791faa0..7eda0433 100644 --- a/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj +++ b/src/EasyCaching.Memcached/EasyCaching.Memcached.csproj @@ -6,10 +6,10 @@ Catcher Wong Catcher Wong $(EasyCachingMemcachedPackageVersion) - - EasyCaching.Memcached based on EasyCaching.Core and EnyimMemcachedCore + + A simple distributed caching provider based on EnyimMemcachedCore. - Caching,Cache,Distributed,Memcached + Memcached,DistributedCache,Caching,Cache https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Memcached/MemcachedServiceCollectionExtensions.cs b/src/EasyCaching.Memcached/MemcachedServiceCollectionExtensions.cs index 9ce1f37d..df95d831 100644 --- a/src/EasyCaching.Memcached/MemcachedServiceCollectionExtensions.cs +++ b/src/EasyCaching.Memcached/MemcachedServiceCollectionExtensions.cs @@ -1,7 +1,9 @@ namespace EasyCaching.Memcached { + using System; + using System.Linq; using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Serialization; using Enyim.Caching.Configuration; using Enyim.Caching.Memcached; using Microsoft.Extensions.Configuration; @@ -9,8 +11,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; - using System; - using System.Linq; /// /// Memcached service collection extensions. diff --git a/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs index 11f53788..dcbc61bb 100644 --- a/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Redis/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Redis { using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; using System; diff --git a/src/EasyCaching.Redis/Configurations/RedisDBOptions.cs b/src/EasyCaching.Redis/Configurations/RedisDBOptions.cs index 4b92b426..bf0ab0aa 100644 --- a/src/EasyCaching.Redis/Configurations/RedisDBOptions.cs +++ b/src/EasyCaching.Redis/Configurations/RedisDBOptions.cs @@ -1,6 +1,6 @@ namespace EasyCaching.Redis { - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; /// /// Redis cache options. diff --git a/src/EasyCaching.Redis/Configurations/RedisOptions.cs b/src/EasyCaching.Redis/Configurations/RedisOptions.cs index ab764b63..887118f2 100644 --- a/src/EasyCaching.Redis/Configurations/RedisOptions.cs +++ b/src/EasyCaching.Redis/Configurations/RedisOptions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.Redis { using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; public class RedisOptions: BaseProviderOptions { diff --git a/src/EasyCaching.Redis/Configurations/RedisOptionsExtension.cs b/src/EasyCaching.Redis/Configurations/RedisOptionsExtension.cs index 67b40477..35f50af1 100755 --- a/src/EasyCaching.Redis/Configurations/RedisOptionsExtension.cs +++ b/src/EasyCaching.Redis/Configurations/RedisOptionsExtension.cs @@ -1,6 +1,8 @@ namespace EasyCaching.Redis { using EasyCaching.Core; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs b/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs index cf6fd095..f1e1c1f6 100755 --- a/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs +++ b/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs @@ -1,14 +1,14 @@ namespace EasyCaching.Redis { - using EasyCaching.Core; - using EasyCaching.Core.Internal; - using Microsoft.Extensions.Logging; - using Microsoft.Extensions.Options; - using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; + using EasyCaching.Core; + using EasyCaching.Core.Serialization; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; + using StackExchange.Redis; /// /// Default redis caching provider. @@ -59,7 +59,7 @@ public partial class DefaultRedisCachingProvider : IEasyCachingProvider /// /// is distributed cache. /// - public bool IsDistributedCache => false; + public bool IsDistributedCache => true; /// /// Gets the order. diff --git a/src/EasyCaching.Redis/EasyCaching.Redis.csproj b/src/EasyCaching.Redis/EasyCaching.Redis.csproj index bdebd0e5..ac4d52b6 100644 --- a/src/EasyCaching.Redis/EasyCaching.Redis.csproj +++ b/src/EasyCaching.Redis/EasyCaching.Redis.csproj @@ -6,10 +6,10 @@ Catcher Wong Catcher Wong $(EasyCachingRedisPackageVersion) - - EasyCaching.Redis based on EasyCaching.Core and StackExchange.Redis + + A simple distributed caching provider based on StackExchange.Redis. - Caching,Cache,Distributed,Redis + Redis,DistributedCache,Caching,Cache https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Redis/RedisCacheServiceCollectionExtensions.cs b/src/EasyCaching.Redis/RedisCacheServiceCollectionExtensions.cs index cafb9333..2b0622b1 100644 --- a/src/EasyCaching.Redis/RedisCacheServiceCollectionExtensions.cs +++ b/src/EasyCaching.Redis/RedisCacheServiceCollectionExtensions.cs @@ -1,13 +1,13 @@ namespace EasyCaching.Redis { + using System; using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Serialization; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; - using System; /// /// Redis cache service collection extensions. diff --git a/src/EasyCaching.ResponseCaching/EasyCaching.ResponseCaching.csproj b/src/EasyCaching.ResponseCaching/EasyCaching.ResponseCaching.csproj index e711c24b..2e51070f 100644 --- a/src/EasyCaching.ResponseCaching/EasyCaching.ResponseCaching.csproj +++ b/src/EasyCaching.ResponseCaching/EasyCaching.ResponseCaching.csproj @@ -7,7 +7,7 @@ Catcher Wong $(EasyCachingResponseCachingPackageVersion) - EasyCaching.ResponseCaching based on EasyCaching.Core and Microsoft.AspNetCore.ResponseCaching + EasyCaching.ResponseCaching is the extension of ResponseCaching Caching,Cache,ResponseCaching https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.ResponseCaching/EasyCachingResponseCachingExtensions.cs b/src/EasyCaching.ResponseCaching/EasyCachingResponseCachingExtensions.cs index 49214b39..d0cd9914 100644 --- a/src/EasyCaching.ResponseCaching/EasyCachingResponseCachingExtensions.cs +++ b/src/EasyCaching.ResponseCaching/EasyCachingResponseCachingExtensions.cs @@ -1,6 +1,6 @@ namespace EasyCaching.ResponseCaching { - using EasyCaching.Core.Internal; + using EasyCaching.Core; using Microsoft.AspNetCore.Builder; /// diff --git a/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs index d033e6fa..cb483505 100644 --- a/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.SQLite/Configurations/EasyCachingOptionsExtensions.cs @@ -1,8 +1,9 @@ namespace EasyCaching.SQLite { + using System; using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.Extensions.Configuration; - using System; /// /// Easy caching options extensions. diff --git a/src/EasyCaching.SQLite/Configurations/SQLiteDBOptions.cs b/src/EasyCaching.SQLite/Configurations/SQLiteDBOptions.cs index 3dd2f5b6..a5c8dab1 100644 --- a/src/EasyCaching.SQLite/Configurations/SQLiteDBOptions.cs +++ b/src/EasyCaching.SQLite/Configurations/SQLiteDBOptions.cs @@ -1,8 +1,8 @@ namespace EasyCaching.SQLite { - using EasyCaching.Core.Internal; - using Microsoft.Data.Sqlite; using System.IO; + using EasyCaching.Core; + using Microsoft.Data.Sqlite; /// /// SQLite cache option. diff --git a/src/EasyCaching.SQLite/Configurations/SQLiteOptions.cs b/src/EasyCaching.SQLite/Configurations/SQLiteOptions.cs index 0da87af3..bade09e0 100644 --- a/src/EasyCaching.SQLite/Configurations/SQLiteOptions.cs +++ b/src/EasyCaching.SQLite/Configurations/SQLiteOptions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.SQLite { using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Configurations; public class SQLiteOptions: BaseProviderOptions { diff --git a/src/EasyCaching.SQLite/Configurations/SQLiteOptionsExtension.cs b/src/EasyCaching.SQLite/Configurations/SQLiteOptionsExtension.cs index ea664cc2..1705958f 100644 --- a/src/EasyCaching.SQLite/Configurations/SQLiteOptionsExtension.cs +++ b/src/EasyCaching.SQLite/Configurations/SQLiteOptionsExtension.cs @@ -2,6 +2,7 @@ { using Dapper; using EasyCaching.Core; + using EasyCaching.Core.Configurations; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj b/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj index 55eba3ee..18a87dbf 100644 --- a/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj +++ b/src/EasyCaching.SQLite/EasyCaching.SQLite.csproj @@ -6,10 +6,10 @@ Catcher Wong Catcher Wong $(EasyCachingSQLitePackageVersion) - - EasyCaching.SQLite based on EasyCaching.Core and Microsoft.Data.SQLite + + A simple local caching provider based on Microsoft.Data.SQLite - Caching,Cache,SQLite + SQLite,LocalCache,Caching,Cache,InMemory,Persisted https://github.com/dotnetcore/EasyCaching https://github.com/dotnetcore/EasyCaching/blob/master/LICENSE https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.SQLite/SQLiteCacheServiceCollectionExtensions.cs b/src/EasyCaching.SQLite/SQLiteCacheServiceCollectionExtensions.cs index f975b1a4..459f4103 100644 --- a/src/EasyCaching.SQLite/SQLiteCacheServiceCollectionExtensions.cs +++ b/src/EasyCaching.SQLite/SQLiteCacheServiceCollectionExtensions.cs @@ -2,7 +2,6 @@ { using System; using EasyCaching.Core; - using EasyCaching.Core.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/EasyCaching.Serialization.Json/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Serialization.Json/Configurations/EasyCachingOptionsExtensions.cs index e10965e8..1d772336 100644 --- a/src/EasyCaching.Serialization.Json/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Serialization.Json/Configurations/EasyCachingOptionsExtensions.cs @@ -1,7 +1,7 @@ namespace EasyCaching.Serialization.Json { - using EasyCaching.Core; using System; + using EasyCaching.Core.Configurations; /// /// EasyCaching options extensions. diff --git a/src/EasyCaching.Serialization.Json/Configurations/JsonOptionsExtension.cs b/src/EasyCaching.Serialization.Json/Configurations/JsonOptionsExtension.cs index 46eef900..f2a03b50 100644 --- a/src/EasyCaching.Serialization.Json/Configurations/JsonOptionsExtension.cs +++ b/src/EasyCaching.Serialization.Json/Configurations/JsonOptionsExtension.cs @@ -1,9 +1,10 @@ namespace EasyCaching.Serialization.Json { - using EasyCaching.Core; + using System; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; - using System; /// /// Json options extension. diff --git a/src/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs b/src/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs index b2aad729..d6689a8c 100644 --- a/src/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs +++ b/src/EasyCaching.Serialization.Json/DefaultJsonSerializer.cs @@ -1,11 +1,10 @@ namespace EasyCaching.Serialization.Json { using System; - using System.Collections.Concurrent; using System.IO; using System.Text; - using EasyCaching.Core; using EasyCaching.Core.Internal; + using EasyCaching.Core.Serialization; using Microsoft.Extensions.Options; using Newtonsoft.Json; diff --git a/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj b/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj index d8716d53..dc35e654 100644 --- a/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj +++ b/src/EasyCaching.Serialization.Json/EasyCaching.Serialization.Json.csproj @@ -6,8 +6,8 @@ Catcher Wong Catcher Wong $(EasyCachingJsonPackageVersion) - - EasyCaching.Serialization.Json based on EasyCaching.Core and Newtonsoft.Json. + + A serialize library based on Newtonsoft.Json Caching,Serialization,Json https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Serialization.Json/JsonSerializerServiceCollectionExtensions.cs b/src/EasyCaching.Serialization.Json/JsonSerializerServiceCollectionExtensions.cs index 0e1d2d60..30cd2af9 100644 --- a/src/EasyCaching.Serialization.Json/JsonSerializerServiceCollectionExtensions.cs +++ b/src/EasyCaching.Serialization.Json/JsonSerializerServiceCollectionExtensions.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Serialization.Json { using EasyCaching.Core; + using EasyCaching.Core.Serialization; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/src/EasyCaching.Serialization.MessagePack/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Serialization.MessagePack/Configurations/EasyCachingOptionsExtensions.cs index a891e164..d432e6cb 100644 --- a/src/EasyCaching.Serialization.MessagePack/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Serialization.MessagePack/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,6 @@ namespace EasyCaching.Serialization.MessagePack { - using EasyCaching.Core; + using EasyCaching.Core.Configurations; /// /// Easy caching options extensions. diff --git a/src/EasyCaching.Serialization.MessagePack/Configurations/MessagePackOptionsExtension.cs b/src/EasyCaching.Serialization.MessagePack/Configurations/MessagePackOptionsExtension.cs index 0b6a286e..2202816d 100644 --- a/src/EasyCaching.Serialization.MessagePack/Configurations/MessagePackOptionsExtension.cs +++ b/src/EasyCaching.Serialization.MessagePack/Configurations/MessagePackOptionsExtension.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Serialization.MessagePack { - using EasyCaching.Core; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; diff --git a/src/EasyCaching.Serialization.MessagePack/DefaultMessagePackSerializer.cs b/src/EasyCaching.Serialization.MessagePack/DefaultMessagePackSerializer.cs index ec9ab39a..56f05576 100644 --- a/src/EasyCaching.Serialization.MessagePack/DefaultMessagePackSerializer.cs +++ b/src/EasyCaching.Serialization.MessagePack/DefaultMessagePackSerializer.cs @@ -1,10 +1,10 @@ namespace EasyCaching.Serialization.MessagePack { - using EasyCaching.Core; using System; + using EasyCaching.Core.Serialization; using global::MessagePack; - using global::MessagePack.Resolvers; - + using global::MessagePack.Resolvers; + /// /// Default messagepack serializer. /// diff --git a/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj b/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj index 80c33699..145c1237 100644 --- a/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj +++ b/src/EasyCaching.Serialization.MessagePack/EasyCaching.Serialization.MessagePack.csproj @@ -6,8 +6,8 @@ Catcher Wong Catcher Wong $(EasyCachingMessagePackPackageVersion) - - EasyCaching.Serialization.MessagePack based on EasyCaching.Core and MessagePack. + + A serialize library based on MessagePack Caching,Serialization,MessagePack https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Serialization.MessagePack/MessagePackSerializerServiceCollectionExtensions.cs b/src/EasyCaching.Serialization.MessagePack/MessagePackSerializerServiceCollectionExtensions.cs index dc32db2a..63cd23cc 100644 --- a/src/EasyCaching.Serialization.MessagePack/MessagePackSerializerServiceCollectionExtensions.cs +++ b/src/EasyCaching.Serialization.MessagePack/MessagePackSerializerServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ namespace EasyCaching.Serialization.MessagePack { - using EasyCaching.Core; - using Microsoft.Extensions.DependencyInjection; using System; + using EasyCaching.Core.Serialization; + using Microsoft.Extensions.DependencyInjection; public static class MessagePackSerializerServiceCollectionExtensions { diff --git a/src/EasyCaching.Serialization.Protobuf/Configurations/EasyCachingOptionsExtensions.cs b/src/EasyCaching.Serialization.Protobuf/Configurations/EasyCachingOptionsExtensions.cs index ceeced95..4977243f 100644 --- a/src/EasyCaching.Serialization.Protobuf/Configurations/EasyCachingOptionsExtensions.cs +++ b/src/EasyCaching.Serialization.Protobuf/Configurations/EasyCachingOptionsExtensions.cs @@ -1,6 +1,6 @@ namespace EasyCaching.Serialization.Protobuf { - using EasyCaching.Core; + using EasyCaching.Core.Configurations; /// /// EasyCaching options extensions. diff --git a/src/EasyCaching.Serialization.Protobuf/Configurations/ProtobufOptionsExtension.cs b/src/EasyCaching.Serialization.Protobuf/Configurations/ProtobufOptionsExtension.cs index 2c2eea87..5adedf3d 100644 --- a/src/EasyCaching.Serialization.Protobuf/Configurations/ProtobufOptionsExtension.cs +++ b/src/EasyCaching.Serialization.Protobuf/Configurations/ProtobufOptionsExtension.cs @@ -1,6 +1,7 @@ namespace EasyCaching.Serialization.Protobuf { - using EasyCaching.Core; + using EasyCaching.Core.Configurations; + using EasyCaching.Core.Serialization; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; diff --git a/src/EasyCaching.Serialization.Protobuf/DefaultProtobufSerializer.cs b/src/EasyCaching.Serialization.Protobuf/DefaultProtobufSerializer.cs index 99c6f323..2e7b6f40 100644 --- a/src/EasyCaching.Serialization.Protobuf/DefaultProtobufSerializer.cs +++ b/src/EasyCaching.Serialization.Protobuf/DefaultProtobufSerializer.cs @@ -1,12 +1,11 @@ namespace EasyCaching.Serialization.Protobuf { - using EasyCaching.Core; - using EasyCaching.Core.Internal; - using ProtoBuf; using System; - using System.Collections.Concurrent; using System.IO; using System.Text; + using EasyCaching.Core.Internal; + using EasyCaching.Core.Serialization; + using ProtoBuf; /// /// Default protobuf serializer. diff --git a/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj b/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj index 5d15b0b2..7e66d6b8 100644 --- a/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj +++ b/src/EasyCaching.Serialization.Protobuf/EasyCaching.Serialization.Protobuf.csproj @@ -6,8 +6,8 @@ Catcher Wong Catcher Wong $(EasyCachingProtobufPackageVersion) - - EasyCaching.Serialization.Protobuf based on EasyCaching.Core and protobuf-net. + + A serialize library based on protobuf-net Caching,Serialization,Protobuf https://github.com/dotnetcore/EasyCaching diff --git a/src/EasyCaching.Serialization.Protobuf/ProtobufSerializerServiceCollectionExtensions.cs b/src/EasyCaching.Serialization.Protobuf/ProtobufSerializerServiceCollectionExtensions.cs index 1412b67d..fc2012d7 100644 --- a/src/EasyCaching.Serialization.Protobuf/ProtobufSerializerServiceCollectionExtensions.cs +++ b/src/EasyCaching.Serialization.Protobuf/ProtobufSerializerServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ namespace EasyCaching.Serialization.Protobuf { - using EasyCaching.Core; - using Microsoft.Extensions.DependencyInjection; using System; + using EasyCaching.Core.Serialization; + using Microsoft.Extensions.DependencyInjection; /// /// Protobuf serializer service collection extensions. diff --git a/test/EasyCaching.PerformanceTests/SerializerBenchmark.cs b/test/EasyCaching.PerformanceTests/SerializerBenchmark.cs index f193ace9..497d1956 100644 --- a/test/EasyCaching.PerformanceTests/SerializerBenchmark.cs +++ b/test/EasyCaching.PerformanceTests/SerializerBenchmark.cs @@ -2,6 +2,7 @@ { using BenchmarkDotNet.Attributes; using EasyCaching.Core; + using EasyCaching.Core.Serialization; using EasyCaching.Serialization.Json; using EasyCaching.Serialization.MessagePack; using EasyCaching.Serialization.Protobuf; diff --git a/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs b/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs index 90ab2b4d..e948f58c 100644 --- a/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/HybridCachingTest.cs @@ -1,92 +1,144 @@ namespace EasyCaching.UnitTests { + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + using EasyCaching.Bus.Redis; using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Bus; using EasyCaching.HybridCache; using EasyCaching.InMemory; using EasyCaching.Redis; - using FakeItEasy; - using Microsoft.Extensions.Caching.Memory; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; - using System; - using System.Collections.Generic; - using System.Threading.Tasks; using Xunit; - public class HybridCachingTest : BaseCachingProviderTest + public class HybridCachingTest //: BaseCachingProviderTest { + + private HybridCachingProvider hybridCaching_1; + private HybridCachingProvider hybridCaching_2; + private IEasyCachingProviderFactory factory; + private string _namespace; public HybridCachingTest() { - RedisOptions options = new RedisOptions(); - options.DBConfig.AllowAdmin = true; - options.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379)); - options.DBConfig.Database = 6; - - var fakeOption = A.Fake>(); - - A.CallTo(() => fakeOption.CurrentValue).Returns(options); + _namespace = "hybrid"; + IServiceCollection services = new ServiceCollection(); + services.AddEasyCaching(option => + { + option.UseInMemory("m1"); + option.UseInMemory("m2"); + + option.UseRedis(config => + { + config.DBConfig.Endpoints.Add(new Core.Configurations.ServerEndPoint("127.0.0.1", 6379)); + config.DBConfig.Database = 5; + }, "myredis"); + + option.WithRedisBus(config => + { + config.Endpoints.Add(new Core.Configurations.ServerEndPoint("127.0.0.1", 6379)); + config.Database = 6; + }); + }); + + IServiceProvider serviceProvider = services.BuildServiceProvider(); + factory = serviceProvider.GetService(); + + var providers_1 = new List + { + factory.GetCachingProvider("m1"), + factory.GetCachingProvider("myredis") + }; - var fakeDbProvider = A.Fake(option => option.WithArgumentsForConstructor(new object[] { fakeOption })); + var providers_2 = new List + { + factory.GetCachingProvider("m2"), + factory.GetCachingProvider("myredis") + }; - var serializer = new DefaultBinaryFormatterSerializer(); + var bus = serviceProvider.GetService(); - var providers = new List + hybridCaching_1 = new HybridCachingProvider(new OptionsWrapper(new HybridCachingOptions { - new DefaultInMemoryCachingProvider(new InMemory.InMemoryCaching(new InMemoryCachingOptions()), new TestOptionMonitorWrapper(new InMemoryOptions())), - new DefaultRedisCachingProvider(fakeDbProvider, serializer, new TestOptionMonitorWrapper(new RedisOptions())) - }; + EnableLogging = false, + TopicName = "test_topic" + }), providers_1, bus); - _provider = new HybridCachingProvider(providers); - _defaultTs = TimeSpan.FromSeconds(30); - _nameSpace = "HybridBasic"; + hybridCaching_2 = new HybridCachingProvider(new OptionsWrapper(new HybridCachingOptions + { + EnableLogging = false, + TopicName = "test_topic" + }), providers_2, bus); } [Fact] - protected override void Get_Count_Without_Prefix_Should_Succeed() + public void Set_And_Get_Should_Succeed() { + var cacheKey = $"{_namespace}_{Guid.NewGuid().ToString()}"; - } + hybridCaching_1.Set(cacheKey, "val", TimeSpan.FromSeconds(30)); - [Fact] - protected override void Get_Count_With_Prefix_Should_Succeed() - { + var res = hybridCaching_1.Get(cacheKey); + Assert.Equal("val", res.Value); } + [Fact] - protected override void OnHit_Should_Return_One_And_OnMiss_Should_Return_Zero() + public async Task SetAsync_And_ExistsAsync_Should_Succeed() { + var cacheKey = $"{_namespace}_{Guid.NewGuid().ToString()}"; - } + await hybridCaching_1.SetAsync(cacheKey, "val", TimeSpan.FromSeconds(30)); - [Fact] - protected override void OnHit_Should_Return_Zero_And_OnMiss_Should_Return_One() - { + var res = await hybridCaching_1.ExistsAsync(cacheKey); + Assert.True(res); } [Fact] - protected override void TrySet_Value_And_Get_Cached_Value_Should_Succeed() + public void Set_And_Remove_Should_Succeed() { + var cacheKey = $"{_namespace}_{Guid.NewGuid().ToString()}"; - } + hybridCaching_1.Set(cacheKey, "val", TimeSpan.FromSeconds(30)); - [Fact] - protected override async Task TrySet_Value_And_Get_Cached_Value_Async_Should_Succeed() - { - await Task.FromResult(1); + hybridCaching_1.Remove(cacheKey); + + var res = hybridCaching_1.Exists(cacheKey); + + Assert.False(res); } [Fact] - protected override void Get_Parallel_Should_Succeed() + public async Task SetAsync_And_RemoveAsync_Should_Succeed() { + var cacheKey = $"{_namespace}_{Guid.NewGuid().ToString()}"; + await hybridCaching_1.SetAsync(cacheKey, "val", TimeSpan.FromSeconds(30)); + + await hybridCaching_1.RemoveAsync(cacheKey); + + var res = await hybridCaching_1.ExistsAsync(cacheKey); + + Assert.False(res); } - [Fact] - protected override Task GetAsync_Parallel_Should_Succeed() + [Fact(Skip = "Delay")] + public void Second_Client_Set_Same_Key_Should_Get_New_Value() { - return Task.FromResult(1); + var cacheKey = $"{_namespace}_{Guid.NewGuid().ToString()}"; + + hybridCaching_1.Set(cacheKey, "val", TimeSpan.FromSeconds(30)); + + hybridCaching_2.Set(cacheKey, "value", TimeSpan.FromSeconds(30)); + + //System.Threading.Thread.Sleep(5000); + + var res = hybridCaching_1.Get(cacheKey); + + Assert.Equal("value", res.Value); } } } diff --git a/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs index 20579c58..042757ec 100644 --- a/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs @@ -1,6 +1,7 @@ namespace EasyCaching.UnitTests { using EasyCaching.Core; + using EasyCaching.Core.Configurations; using EasyCaching.Core.Internal; using EasyCaching.Redis; using Microsoft.Extensions.DependencyInjection; diff --git a/test/EasyCaching.UnitTests/CachingTests/SERedisFeatureCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/SERedisFeatureCachingProviderTest.cs index eca1c6e8..0159ca71 100644 --- a/test/EasyCaching.UnitTests/CachingTests/SERedisFeatureCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/SERedisFeatureCachingProviderTest.cs @@ -1,6 +1,7 @@ namespace EasyCaching.UnitTests { - using EasyCaching.Core; + using EasyCaching.Core; + using EasyCaching.Core.Configurations; using EasyCaching.Core.Internal; using EasyCaching.Redis; using Microsoft.Extensions.DependencyInjection; diff --git a/test/EasyCaching.UnitTests/Core/ArgumentCheckTest.cs b/test/EasyCaching.UnitTests/Core/ArgumentCheckTest.cs index d445cd47..5cf7ce7c 100644 --- a/test/EasyCaching.UnitTests/Core/ArgumentCheckTest.cs +++ b/test/EasyCaching.UnitTests/Core/ArgumentCheckTest.cs @@ -1,6 +1,6 @@ namespace EasyCaching.UnitTests { - using EasyCaching.Core.Internal; + using EasyCaching.Core; using System; using Xunit; using System.Collections.Generic; diff --git a/test/EasyCaching.UnitTests/Core/DefaultEasyCachingKeyGeneratorTest.cs b/test/EasyCaching.UnitTests/Core/DefaultEasyCachingKeyGeneratorTest.cs index 0035e43e..cb7e00fe 100644 --- a/test/EasyCaching.UnitTests/Core/DefaultEasyCachingKeyGeneratorTest.cs +++ b/test/EasyCaching.UnitTests/Core/DefaultEasyCachingKeyGeneratorTest.cs @@ -4,8 +4,7 @@ using System.Reflection; using System.Security.Cryptography; using System.Text; - using EasyCaching.Core; - using EasyCaching.Core.Internal; + using EasyCaching.Core.Interceptor; using Xunit; public class DefaultEasyCachingKeyGeneratorTest diff --git a/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj b/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj index d9df9e39..0858e4d6 100644 --- a/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj +++ b/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj @@ -30,6 +30,8 @@ + + diff --git a/test/EasyCaching.UnitTests/Infrastructure/IExampleService.cs b/test/EasyCaching.UnitTests/Infrastructure/IExampleService.cs index ac86f610..2d046cf1 100644 --- a/test/EasyCaching.UnitTests/Infrastructure/IExampleService.cs +++ b/test/EasyCaching.UnitTests/Infrastructure/IExampleService.cs @@ -1,9 +1,9 @@ namespace EasyCaching.UnitTests.Infrastructure { - using EasyCaching.Core.Internal; using System; - using System.Threading.Tasks; using System.Collections.Generic; + using System.Threading.Tasks; + using EasyCaching.Core.Interceptor; public interface ICastleExampleService { diff --git a/test/EasyCaching.UnitTests/InterceptorTests/AspectCoreInterceptorTest.cs b/test/EasyCaching.UnitTests/InterceptorTests/AspectCoreInterceptorTest.cs index 05bb08a6..9f5bb329 100755 --- a/test/EasyCaching.UnitTests/InterceptorTests/AspectCoreInterceptorTest.cs +++ b/test/EasyCaching.UnitTests/InterceptorTests/AspectCoreInterceptorTest.cs @@ -1,16 +1,15 @@ namespace EasyCaching.UnitTests { - using AspectCore.Configuration; - using AspectCore.Injector; + using System; + using System.Linq; + using System.Threading; + using System.Threading.Tasks; using EasyCaching.Core; + using EasyCaching.Core.Interceptor; using EasyCaching.InMemory; using EasyCaching.Interceptor.AspectCore; using EasyCaching.UnitTests.Infrastructure; using Microsoft.Extensions.DependencyInjection; - using System; - using System.Linq; - using System.Threading; - using System.Threading.Tasks; using Xunit; public abstract class BaseAspectCoreInterceptorTest diff --git a/test/EasyCaching.UnitTests/InterceptorTests/CastleInterceptorTest.cs b/test/EasyCaching.UnitTests/InterceptorTests/CastleInterceptorTest.cs index 1b9a40eb..d505070d 100755 --- a/test/EasyCaching.UnitTests/InterceptorTests/CastleInterceptorTest.cs +++ b/test/EasyCaching.UnitTests/InterceptorTests/CastleInterceptorTest.cs @@ -1,20 +1,20 @@ namespace EasyCaching.UnitTests { - using EasyCaching.Core.Internal; - using EasyCaching.UnitTests.Infrastructure; - using EasyCaching.Interceptor.Castle; - using EasyCaching.InMemory; using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; using System.Threading; - using Xunit; - using Microsoft.Extensions.DependencyInjection; - using EasyCaching.Core; + using System.Threading.Tasks; using Autofac; - using System.Reflection; using Autofac.Extras.DynamicProxy; - using System.Threading.Tasks; - using System.Linq; - using System.Collections.Generic; + using EasyCaching.Core; + using EasyCaching.Core.Interceptor; + using EasyCaching.InMemory; + using EasyCaching.Interceptor.Castle; + using EasyCaching.UnitTests.Infrastructure; + using Microsoft.Extensions.DependencyInjection; + using Xunit; public abstract class BaseCastleInterceptorTest { diff --git a/test/EasyCaching.UnitTests/SerializerTests/BaseSerializerTest.cs b/test/EasyCaching.UnitTests/SerializerTests/BaseSerializerTest.cs index abcbe5f5..49dbcda4 100644 --- a/test/EasyCaching.UnitTests/SerializerTests/BaseSerializerTest.cs +++ b/test/EasyCaching.UnitTests/SerializerTests/BaseSerializerTest.cs @@ -1,9 +1,9 @@ namespace EasyCaching.UnitTests { - using EasyCaching.Core; using System; - using Xunit; + using EasyCaching.Core.Serialization; using ProtoBuf; + using Xunit; public abstract class BaseSerializerTest { diff --git a/test/EasyCaching.UnitTests/SerializerTests/BinaryFormatterSerializerTest.cs b/test/EasyCaching.UnitTests/SerializerTests/BinaryFormatterSerializerTest.cs index 8aa77e54..829b5878 100644 --- a/test/EasyCaching.UnitTests/SerializerTests/BinaryFormatterSerializerTest.cs +++ b/test/EasyCaching.UnitTests/SerializerTests/BinaryFormatterSerializerTest.cs @@ -1,6 +1,6 @@ namespace EasyCaching.UnitTests { - using EasyCaching.Core; + using EasyCaching.Core.Serialization; public class BinaryFormatterSerializerTest : BaseSerializerTest { diff --git a/test/EasyCaching.UnitTests/SerializerTests/SerializerServiceCollectionExtensionsTest.cs b/test/EasyCaching.UnitTests/SerializerTests/SerializerServiceCollectionExtensionsTest.cs index 55137c19..7e466e4d 100644 --- a/test/EasyCaching.UnitTests/SerializerTests/SerializerServiceCollectionExtensionsTest.cs +++ b/test/EasyCaching.UnitTests/SerializerTests/SerializerServiceCollectionExtensionsTest.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using System; using Xunit; + using EasyCaching.Core.Serialization; public class SerializerServiceCollectionExtensionsTest {