Skip to content

Commit 40db227

Browse files
authored
Merge pull request #76 from dotnetcore/dev
Hybrid Caching Provider
2 parents a394029 + b8b39b1 commit 40db227

File tree

133 files changed

+1470
-1252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1470
-1252
lines changed

build/releasenotes.props

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
<Project>
22
<PropertyGroup>
33
<EasyCachingCorePackageNotes>
4-
1. Add IRedisCachingProvider.
4+
1. EasyCaching Bus
5+
2. HybridCaching
56
</EasyCachingCorePackageNotes>
67
<EasyCachingMemcachedPackageNotes>
7-
1. Improve Get cached value.
8+
1. Adjust reference namespace.
89
</EasyCachingMemcachedPackageNotes>
910
<EasyCachingRedisPackageNotes>
10-
1. Add Impl of IRedisCachingProvider.
11+
1. Adjust reference namespace.
1112
</EasyCachingRedisPackageNotes>
1213
<EasyCachingSQLitePackageNotes>
13-
1. Improve Configuration.
14+
1. Adjust reference namespace.
1415
</EasyCachingSQLitePackageNotes>
1516
<EasyCachingInMemoryPackageNotes>
16-
1. Update Options.
17-
2. Improve Get cached value.
17+
1. Adjust reference namespace.
1818
</EasyCachingInMemoryPackageNotes>
1919
<EasyCachingHybridPackageNotes>
20-
1. Improve Configuration.
20+
1. Refactor.
2121
</EasyCachingHybridPackageNotes>
2222
<EasyCachingAspectCorePackageNotes>
23-
1. Fixed bug of IConvertible.
23+
1. Adjust reference namespace.
2424
</EasyCachingAspectCorePackageNotes>
2525
<EasyCachingCastlePackageNotes>
26-
1. Remove Dependency of IEasyCaching.
26+
1. Adjust reference namespace.
2727
</EasyCachingCastlePackageNotes>
2828
<EasyCachingResponseCachingPackageNotes>
29-
1. Support .NET Core 2.1
29+
1. Adjust reference namespace.
3030
</EasyCachingResponseCachingPackageNotes>
3131
<EasyCachingJsonPackageNotes>
32-
1. Improve Configuration.
32+
1. Adjust reference namespace.
3333
</EasyCachingJsonPackageNotes>
3434
<EasyCachingMessagePackPackageNotes>
35-
1. Improve Configuration.
35+
1. Adjust reference namespace.
3636
</EasyCachingMessagePackPackageNotes>
3737
<EasyCachingProtobufPackageNotes>
38-
1. Improve Configuration.
38+
1. Adjust reference namespace.
3939
</EasyCachingProtobufPackageNotes>
4040
<EasyCachingCSRedisPackageNotes>
41-
1. Init.
41+
1. Adjust reference namespace.
4242
</EasyCachingCSRedisPackageNotes>
43+
<EasyCachingRedisBusPackageNotes>
44+
1. Init.
45+
</EasyCachingRedisBusPackageNotes>
46+
<EasyCachingRabbitBusPackageNotes>
47+
1. Init.
48+
</EasyCachingRabbitBusPackageNotes>
4349
</PropertyGroup>
4450
</Project>

build/version.props

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<Project>
22
<PropertyGroup>
3-
<EasyCachingCorePackageVersion>0.4.6</EasyCachingCorePackageVersion>
4-
<EasyCachingMemcachedPackageVersion>0.4.5.1</EasyCachingMemcachedPackageVersion>
5-
<EasyCachingRedisPackageVersion>0.4.6</EasyCachingRedisPackageVersion>
6-
<EasyCachingSQLitePackageVersion>0.4.5</EasyCachingSQLitePackageVersion>
7-
<EasyCachingInMemoryPackageVersion>0.4.6</EasyCachingInMemoryPackageVersion>
8-
<EasyCachingHybridPackageVersion>0.4.5</EasyCachingHybridPackageVersion>
9-
<EasyCachingAspectCorePackageVersion>0.3.3</EasyCachingAspectCorePackageVersion>
10-
<EasyCachingCastlePackageVersion>0.3.2</EasyCachingCastlePackageVersion>
11-
<EasyCachingResponseCachingPackageVersion>0.3.0</EasyCachingResponseCachingPackageVersion>
12-
<EasyCachingJsonPackageVersion>0.3.5</EasyCachingJsonPackageVersion>
13-
<EasyCachingMessagePackPackageVersion>0.3.5</EasyCachingMessagePackPackageVersion>
14-
<EasyCachingProtobufPackageVersion>0.3.5</EasyCachingProtobufPackageVersion>
15-
<EasyCachingCSRedisPackageVersion>0.1.0</EasyCachingCSRedisPackageVersion>
3+
<EasyCachingCorePackageVersion>0.5.0</EasyCachingCorePackageVersion>
4+
<EasyCachingMemcachedPackageVersion>0.5.0</EasyCachingMemcachedPackageVersion>
5+
<EasyCachingRedisPackageVersion>0.5.0</EasyCachingRedisPackageVersion>
6+
<EasyCachingSQLitePackageVersion>0.5.0</EasyCachingSQLitePackageVersion>
7+
<EasyCachingInMemoryPackageVersion>0.5.0</EasyCachingInMemoryPackageVersion>
8+
<EasyCachingHybridPackageVersion>0.5.0</EasyCachingHybridPackageVersion>
9+
<EasyCachingAspectCorePackageVersion>0.5.0</EasyCachingAspectCorePackageVersion>
10+
<EasyCachingCastlePackageVersion>0.5.0</EasyCachingCastlePackageVersion>
11+
<EasyCachingResponseCachingPackageVersion>0.5.0</EasyCachingResponseCachingPackageVersion>
12+
<EasyCachingJsonPackageVersion>0.5.0</EasyCachingJsonPackageVersion>
13+
<EasyCachingMessagePackPackageVersion>0.5.0</EasyCachingMessagePackPackageVersion>
14+
<EasyCachingProtobufPackageVersion>0.5.0</EasyCachingProtobufPackageVersion>
15+
<EasyCachingCSRedisPackageVersion>0.5.0</EasyCachingCSRedisPackageVersion>
16+
<EasyCachingRedisBusPackageVersion>0.5.0</EasyCachingRedisBusPackageVersion>
17+
<EasyCachingRabbitBusPackageVersion>0.5.0-alpha</EasyCachingRabbitBusPackageVersion>
1618
</PropertyGroup>
1719
</Project>

media/hybrid_details.png

50 KB
Loading

sample/EasyCaching.Demo.Interceptors/Services/IAspectCoreService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace EasyCaching.Demo.Interceptors.Services
22
{
3-
using EasyCaching.Core.Internal;
43
using System.Threading.Tasks;
5-
4+
using EasyCaching.Core.Interceptor;
5+
66
public interface IAspectCoreService //: EasyCaching.Core.Internal.IEasyCaching
77
{
88
[EasyCachingAble(Expiration = 10)]

sample/EasyCaching.Demo.Interceptors/Services/ICastleService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace EasyCaching.Demo.Interceptors.Services
22
{
33
using System.Threading.Tasks;
4+
using EasyCaching.Core.Interceptor;
45
using EasyCaching.Core.Internal;
56

67
public interface ICastleService

sample/EasyCaching.Demo.Providers/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Extensions.DependencyInjection;
1616
using Microsoft.Extensions.Logging;
1717
using System;
18+
using EasyCaching.Core.Configurations;
1819

1920
public class Startup
2021
{
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace EasyCaching.Bus.RabbitMQ
2+
{
3+
using Microsoft.Extensions.ObjectPool;
4+
using Microsoft.Extensions.Options;
5+
using global::RabbitMQ.Client;
6+
7+
/// <summary>
8+
/// Connection pooled object policy.
9+
/// </summary>
10+
public class ConnectionPooledObjectPolicy : IPooledObjectPolicy<IConnection>
11+
{
12+
/// <summary>
13+
/// The options.
14+
/// </summary>
15+
private readonly RabbitMQBusOptions _options;
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.ConnectionPooledObjectPolicy"/> class.
19+
/// </summary>
20+
/// <param name="optionsAccs">Options accs.</param>
21+
public ConnectionPooledObjectPolicy(IOptions<RabbitMQBusOptions> optionsAccs)
22+
{
23+
this._options = optionsAccs.Value;
24+
}
25+
26+
/// <summary>
27+
/// Create this instance.
28+
/// </summary>
29+
/// <returns>The create.</returns>
30+
public IConnection Create()
31+
{
32+
var factory = new ConnectionFactory
33+
{
34+
HostName = _options.HostName,
35+
UserName = _options.UserName,
36+
Port = _options.Port,
37+
Password = _options.Password,
38+
VirtualHost = _options.VirtualHost,
39+
RequestedConnectionTimeout = _options.RequestedConnectionTimeout,
40+
SocketReadTimeout = _options.SocketReadTimeout,
41+
SocketWriteTimeout = _options.SocketWriteTimeout
42+
};
43+
44+
var connection = factory.CreateConnection();
45+
return connection;
46+
}
47+
48+
/// <summary>
49+
/// Return the specified connection.
50+
/// </summary>
51+
/// <returns>The return.</returns>
52+
/// <param name="connection">Connection.</param>
53+
public bool Return(IConnection connection)
54+
{
55+
return true;
56+
}
57+
}
58+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
namespace EasyCaching.Bus.RabbitMQ
2+
{
3+
using System;
4+
using EasyCaching.Core.Configurations;
5+
using Microsoft.Extensions.Configuration;
6+
7+
/// <summary>
8+
/// EasyCaching options extensions.
9+
/// </summary>
10+
public static class EasyCachingOptionsExtensions
11+
{
12+
/// <summary>
13+
/// Withs the RabbitMQ Bus.
14+
/// </summary>
15+
/// <returns>The rabbit MQB us.</returns>
16+
/// <param name="options">Options.</param>
17+
/// <param name="configure">Configure.</param>
18+
public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, Action<RabbitMQBusOptions> configure)
19+
{
20+
if (configure == null)
21+
{
22+
throw new ArgumentNullException(nameof(configure));
23+
}
24+
25+
options.RegisterExtension(new RabbitMQBusOptionsExtension(configure));
26+
return options;
27+
}
28+
29+
/// <summary>
30+
/// Withs the RabbitMQ Bus.
31+
/// </summary>
32+
/// <returns>The rabbit MQB us.</returns>
33+
/// <param name="options">Options.</param>
34+
/// <param name="configuration">Configuration.</param>
35+
/// <param name="sectionName">Section name.</param>
36+
public static EasyCachingOptions WithRabbitMQBus(this EasyCachingOptions options, IConfiguration configuration, string sectionName = "rabbitmqbus")
37+
{
38+
var dbConfig = configuration.GetSection(sectionName);
39+
var busOptions = new RabbitMQBusOptions();
40+
dbConfig.Bind(busOptions);
41+
42+
void configure(RabbitMQBusOptions x)
43+
{
44+
x.HostName = busOptions.HostName;
45+
x.Password = busOptions.Password;
46+
x.Port = busOptions.Port;
47+
x.QueueMessageExpires = busOptions.QueueMessageExpires;
48+
x.RequestedConnectionTimeout = busOptions.RequestedConnectionTimeout;
49+
x.RouteKey = busOptions.RouteKey;
50+
x.SocketReadTimeout = busOptions.SocketReadTimeout;
51+
x.SocketWriteTimeout = busOptions.SocketWriteTimeout;
52+
x.TopicExchangeName = busOptions.TopicExchangeName;
53+
x.UserName = busOptions.UserName;
54+
x.VirtualHost = busOptions.VirtualHost;
55+
x.QueueName = busOptions.QueueName;
56+
}
57+
58+
options.RegisterExtension(new RabbitMQBusOptionsExtension(configure));
59+
return options;
60+
}
61+
}
62+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace EasyCaching.Bus.RabbitMQ
2+
{
3+
using EasyCaching.Core.Configurations;
4+
5+
/// <summary>
6+
/// RabbitMQ Bus options.
7+
/// </summary>
8+
public class RabbitMQBusOptions : BaseRabbitMQOptions
9+
{
10+
/// <summary>
11+
/// Gets or sets the route key.
12+
/// </summary>
13+
/// <value>The route key.</value>
14+
public string RouteKey { get; set; } = "rmq.queue.undurable.easycaching.subscriber.*";
15+
16+
/// <summary>
17+
/// Gets or sets the name of the queue.
18+
/// </summary>
19+
/// <value>The name of the queue.</value>
20+
public string QueueName { get; set; } = "";
21+
}
22+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace EasyCaching.Bus.RabbitMQ
2+
{
3+
using System;
4+
using EasyCaching.Core.Bus;
5+
using EasyCaching.Core.Configurations;
6+
using EasyCaching.Core.Serialization;
7+
using global::RabbitMQ.Client;
8+
using Microsoft.AspNetCore.Builder;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.DependencyInjection.Extensions;
11+
using Microsoft.Extensions.ObjectPool;
12+
13+
/// <summary>
14+
/// RabbitMQ Bus options extension.
15+
/// </summary>
16+
public class RabbitMQBusOptionsExtension : IEasyCachingOptionsExtension
17+
{
18+
/// <summary>
19+
/// The configure.
20+
/// </summary>
21+
private readonly Action<RabbitMQBusOptions> configure;
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="T:EasyCaching.Bus.RabbitMQ.RabbitMQBusOptionsExtension"/> class.
25+
/// </summary>
26+
/// <param name="configure">Configure.</param>
27+
public RabbitMQBusOptionsExtension(Action<RabbitMQBusOptions> configure)
28+
{
29+
this.configure = configure;
30+
}
31+
32+
/// <summary>
33+
/// Adds the services.
34+
/// </summary>
35+
/// <param name="services">Services.</param>
36+
public void AddServices(IServiceCollection services)
37+
{
38+
services.AddOptions();
39+
services.Configure(configure);
40+
41+
services.TryAddSingleton<IEasyCachingSerializer, DefaultBinaryFormatterSerializer>();
42+
services.AddSingleton<IPooledObjectPolicy<IConnection>, ConnectionPooledObjectPolicy>();
43+
services.AddSingleton<IEasyCachingBus, DefaultRabbitMQBus>();
44+
}
45+
46+
/// <summary>
47+
/// Withs the services.
48+
/// </summary>
49+
/// <param name="services">Services.</param>
50+
public void WithServices(IApplicationBuilder services)
51+
{
52+
// Method intentionally left empty.
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)