Skip to content

Commit 395453f

Browse files
committed
refactor: IClient support Isolation
1 parent ed1f72d commit 395453f

File tree

47 files changed

+767
-193
lines changed

Some content is hidden

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

47 files changed

+767
-193
lines changed

src/BuildingBlocks/Caching/Masa.BuildingBlocks.Caching/Default/CacheClientFactoryBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Masa.BuildingBlocks.Caching;
55

6-
public abstract class CacheClientFactoryBase<TService> : MasaFactoryBase<TService, CacheRelationOptions<TService>>,
6+
public abstract class CacheClientFactoryBase<TService> : MasaFactoryBase<TService, MasaRelationOptions<TService>>,
77
ICacheClientFactory<TService> where TService : class
88
{
99
protected CacheClientFactoryBase(IServiceProvider serviceProvider) : base(serviceProvider)

src/BuildingBlocks/Caching/Masa.BuildingBlocks.Caching/Default/DefaultDistributedCacheClientFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protected override string DefaultServiceNotFoundMessage
1010

1111
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] DistributedCache, it was not found";
1212

13-
protected override MasaFactoryOptions<CacheRelationOptions<IManualDistributedCacheClient>> FactoryOptions => _optionsMonitor.CurrentValue;
13+
protected override MasaFactoryOptions<MasaRelationOptions<IManualDistributedCacheClient>> FactoryOptions => _optionsMonitor.CurrentValue;
1414

1515
private readonly IOptionsMonitor<DistributedCacheFactoryOptions> _optionsMonitor;
1616

src/BuildingBlocks/Caching/Masa.BuildingBlocks.Caching/Default/DefaultMultilevelCacheClientFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protected override string DefaultServiceNotFoundMessage
1010

1111
protected override string SpecifyServiceNotFoundMessage => "Please make sure you have used [{0}] MultilevelCache, it was not found";
1212

13-
protected override MasaFactoryOptions<CacheRelationOptions<IManualMultilevelCacheClient>> FactoryOptions
13+
protected override MasaFactoryOptions<MasaRelationOptions<IManualMultilevelCacheClient>> FactoryOptions
1414
=> _optionsMonitor.CurrentValue;
1515

1616
private readonly IOptionsMonitor<MultilevelCacheFactoryOptions> _optionsMonitor;

src/BuildingBlocks/Caching/Masa.BuildingBlocks.Caching/Extensions/DistributedCacheBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void UseCustomDistributedCache(
1616
if (options.Options.Any(opt => opt.Name == distributedCacheBuilder.Name))
1717
return;
1818

19-
options.Options.Add(new CacheRelationOptions<IManualDistributedCacheClient>(distributedCacheBuilder.Name, func));
19+
options.Options.Add(new MasaRelationOptions<IManualDistributedCacheClient>(distributedCacheBuilder.Name, func));
2020
});
2121

2222
distributedCacheBuilder.Services.TryAddDistributedCache(distributedCacheBuilder.Name);

src/BuildingBlocks/Caching/Masa.BuildingBlocks.Caching/Extensions/MultilevelCacheBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void UseCustomMultilevelCache(
1616
if (options.Options.Any(opt => opt.Name == multilevelCacheBuilder.Name))
1717
return;
1818

19-
var cacheRelationOptions = new CacheRelationOptions<IManualMultilevelCacheClient>(multilevelCacheBuilder.Name, func.Invoke);
19+
var cacheRelationOptions = new MasaRelationOptions<IManualMultilevelCacheClient>(multilevelCacheBuilder.Name, func.Invoke);
2020
options.Options.Add(cacheRelationOptions);
2121
});
2222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
// ReSharper disable once CheckNamespace
5+
6+
namespace Masa.BuildingBlocks.Caching;
7+
8+
internal class DefaultDistributedCacheClient : IManualDistributedCacheClient
9+
{
10+
private readonly IManualDistributedCacheClient _cacheClient;
11+
public DefaultDistributedCacheClient(IManualDistributedCacheClient cacheClient) => _cacheClient = cacheClient;
12+
13+
public IEnumerable<T?> GetList<T>(params string[] keys) => _cacheClient.GetList<T>(keys);
14+
15+
public Task<IEnumerable<T?>> GetListAsync<T>(params string[] keys) => _cacheClient.GetListAsync<T>(keys);
16+
17+
public void Set<T>(string key, T value, DateTimeOffset? absoluteExpiration, Action<CacheOptions>? action = null)
18+
=> _cacheClient.Set(key, value, absoluteExpiration, action);
19+
20+
public void Set<T>(string key, T value, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null)
21+
=> _cacheClient.Set(key, value, absoluteExpirationRelativeToNow, action);
22+
23+
public void Set<T>(string key, T value, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
24+
=> _cacheClient.Set(key, value, options, action);
25+
26+
public Task SetAsync<T>(string key, T value, DateTimeOffset? absoluteExpiration, Action<CacheOptions>? action = null)
27+
=> _cacheClient.SetAsync(key, value, absoluteExpiration, action);
28+
29+
public Task SetAsync<T>(string key, T value, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null)
30+
=> _cacheClient.SetAsync(key, value, absoluteExpirationRelativeToNow, action);
31+
32+
public Task SetAsync<T>(string key, T value, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
33+
=> _cacheClient.SetAsync(key, value, options, action);
34+
35+
public void SetList<T>(Dictionary<string, T?> keyValues, DateTimeOffset? absoluteExpiration, Action<CacheOptions>? action = null)
36+
=> _cacheClient.SetList(keyValues, absoluteExpiration, action);
37+
38+
public void SetList<T>(Dictionary<string, T?> keyValues, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null)
39+
=> _cacheClient.SetList(keyValues, absoluteExpirationRelativeToNow, action);
40+
41+
public void SetList<T>(Dictionary<string, T?> keyValues, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
42+
=> _cacheClient.SetList(keyValues, options, action);
43+
44+
public Task SetListAsync<T>(Dictionary<string, T?> keyValues, DateTimeOffset? absoluteExpiration, Action<CacheOptions>? action = null)
45+
=> _cacheClient.SetListAsync(keyValues, absoluteExpiration, action);
46+
47+
public Task SetListAsync<T>(
48+
Dictionary<string, T?> keyValues,
49+
TimeSpan? absoluteExpirationRelativeToNow,
50+
Action<CacheOptions>? action = null)
51+
=> _cacheClient.SetListAsync(keyValues, absoluteExpirationRelativeToNow, action);
52+
53+
public Task SetListAsync<T>(Dictionary<string, T?> keyValues, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
54+
=> _cacheClient.SetListAsync(keyValues, options, action);
55+
56+
public void Remove<T>(string key, Action<CacheOptions>? action = null)
57+
=> _cacheClient.Remove<T>(key, action);
58+
59+
public void Remove<T>(IEnumerable<string> keys, Action<CacheOptions>? action = null)
60+
=> _cacheClient.Remove<T>(keys, action);
61+
62+
public Task RemoveAsync<T>(string key, Action<CacheOptions>? action = null)
63+
=> _cacheClient.RemoveAsync<T>(key, action);
64+
65+
public Task RemoveAsync<T>(IEnumerable<string> keys, Action<CacheOptions>? action = null)
66+
=> _cacheClient.RemoveAsync<T>(keys, action);
67+
68+
public void Refresh<T>(IEnumerable<string> keys, Action<CacheOptions>? action = null)
69+
=> _cacheClient.Refresh<T>(keys, action);
70+
71+
public Task RefreshAsync<T>(IEnumerable<string> keys, Action<CacheOptions>? action = null)
72+
=> _cacheClient.RefreshAsync<T>(keys, action);
73+
74+
public T? Get<T>(string key, Action<CacheOptions>? action = null)
75+
=> _cacheClient.Get<T>(key, action);
76+
77+
public Task<T?> GetAsync<T>(string key, Action<CacheOptions>? action = null)
78+
=> _cacheClient.GetAsync<T>(key, action);
79+
80+
public IEnumerable<T?> GetList<T>(IEnumerable<string> keys, Action<CacheOptions>? action = null)
81+
=> _cacheClient.GetList<T>(keys, action);
82+
83+
public Task<IEnumerable<T?>> GetListAsync<T>(IEnumerable<string> keys, Action<CacheOptions>? action = null)
84+
=> _cacheClient.GetListAsync<T>(keys, action);
85+
86+
public T? GetOrSet<T>(string key, Func<CacheEntry<T>> setter, Action<CacheOptions>? action = null)
87+
=> _cacheClient.GetOrSet(key, setter, action);
88+
89+
public Task<T?> GetOrSetAsync<T>(string key, Func<CacheEntry<T>> setter, Action<CacheOptions>? action = null)
90+
=> _cacheClient.GetOrSetAsync(key, setter, action);
91+
92+
public Task<T?> GetOrSetAsync<T>(string key, Func<Task<CacheEntry<T>>> setter, Action<CacheOptions>? action = null)
93+
=> _cacheClient.GetOrSetAsync(key, setter, action);
94+
95+
public void Refresh(params string[] keys)
96+
=> _cacheClient.Refresh(keys);
97+
98+
public Task RefreshAsync(params string[] keys)
99+
=> _cacheClient.RefreshAsync(keys);
100+
101+
public void Remove(params string[] keys)
102+
=> _cacheClient.Remove(keys);
103+
104+
public Task RemoveAsync(params string[] keys)
105+
=> _cacheClient.RemoveAsync(keys);
106+
107+
public bool Exists(string key)
108+
=> _cacheClient.Exists(key);
109+
110+
public bool Exists<T>(string key, Action<CacheOptions>? action = null)
111+
=> _cacheClient.Exists<T>(key, action);
112+
113+
public Task<bool> ExistsAsync(string key)
114+
=> _cacheClient.ExistsAsync(key);
115+
116+
public Task<bool> ExistsAsync<T>(string key, Action<CacheOptions>? action = null)
117+
=> _cacheClient.ExistsAsync<T>(key, action);
118+
119+
public IEnumerable<string> GetKeys(string keyPattern)
120+
=> _cacheClient.GetKeys(keyPattern);
121+
122+
public IEnumerable<string> GetKeys<T>(string keyPattern, Action<CacheOptions>? action = null)
123+
=> _cacheClient.GetKeys<T>(keyPattern, action);
124+
125+
public Task<IEnumerable<string>> GetKeysAsync(string keyPattern)
126+
=> _cacheClient.GetKeysAsync(keyPattern);
127+
128+
public Task<IEnumerable<string>> GetKeysAsync<T>(string keyPattern, Action<CacheOptions>? action = null)
129+
=> _cacheClient.GetKeysAsync<T>(keyPattern, action);
130+
131+
public IEnumerable<KeyValuePair<string, T?>> GetByKeyPattern<T>(string keyPattern, Action<CacheOptions>? action = null)
132+
=> _cacheClient.GetByKeyPattern<T>(keyPattern, action);
133+
134+
public Task<IEnumerable<KeyValuePair<string, T?>>> GetByKeyPatternAsync<T>(string keyPattern, Action<CacheOptions>? action = null)
135+
=> _cacheClient.GetByKeyPatternAsync<T>(keyPattern, action);
136+
137+
public void Publish(string channel, Action<PublishOptions> options)
138+
=> _cacheClient.Publish(channel, options);
139+
140+
public Task PublishAsync(string channel, Action<PublishOptions> options)
141+
=> _cacheClient.PublishAsync(channel, options);
142+
143+
public void Subscribe<T>(string channel, Action<SubscribeOptions<T>> options)
144+
=> _cacheClient.Subscribe(channel, options);
145+
146+
public Task SubscribeAsync<T>(string channel, Action<SubscribeOptions<T>> options)
147+
=> _cacheClient.SubscribeAsync(channel, options);
148+
149+
public void UnSubscribe<T>(string channel)
150+
=> _cacheClient.UnSubscribe<T>(channel);
151+
152+
public Task UnSubscribeAsync<T>(string channel)
153+
=> _cacheClient.UnSubscribeAsync<T>(channel);
154+
155+
public Task<long> HashIncrementAsync(string key, long value = 1, Action<CacheOptions>? action = null, CacheEntryOptions? options = null)
156+
=> _cacheClient.HashIncrementAsync(key, value, action, options);
157+
158+
public Task<long?> HashDecrementAsync(
159+
string key,
160+
long value = 1,
161+
long defaultMinVal = 0,
162+
Action<CacheOptions>? action = null,
163+
CacheEntryOptions? options = null)
164+
=> _cacheClient.HashDecrementAsync(key, value, defaultMinVal, action, options);
165+
166+
public bool KeyExpire(string key, TimeSpan? absoluteExpirationRelativeToNow)
167+
=> _cacheClient.KeyExpire(key, absoluteExpirationRelativeToNow);
168+
169+
public bool KeyExpire<T>(string key, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null)
170+
=> _cacheClient.KeyExpire<T>(key, absoluteExpirationRelativeToNow, action);
171+
172+
public bool KeyExpire(string key, DateTimeOffset absoluteExpiration)
173+
=> _cacheClient.KeyExpire(key, absoluteExpiration);
174+
175+
public bool KeyExpire<T>(string key, DateTimeOffset absoluteExpiration, Action<CacheOptions>? action = null)
176+
=> _cacheClient.KeyExpire<T>(key, absoluteExpiration, action);
177+
178+
public bool KeyExpire(string key, CacheEntryOptions? options = null)
179+
=> _cacheClient.KeyExpire(key, options);
180+
181+
public bool KeyExpire<T>(string key, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
182+
=> _cacheClient.KeyExpire<T>(key, options, action);
183+
184+
public long KeyExpire(IEnumerable<string> keys, CacheEntryOptions? options = null)
185+
=> _cacheClient.KeyExpire(keys, options);
186+
187+
public long KeyExpire<T>(IEnumerable<string> keys, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
188+
=> _cacheClient.KeyExpire<T>(keys, options, action);
189+
190+
public Task<bool> KeyExpireAsync(string key, TimeSpan? absoluteExpirationRelativeToNow)
191+
=> _cacheClient.KeyExpireAsync(key, absoluteExpirationRelativeToNow);
192+
193+
public Task<bool> KeyExpireAsync<T>(string key, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null)
194+
=> _cacheClient.KeyExpireAsync<T>(key, absoluteExpirationRelativeToNow, action);
195+
196+
public Task<bool> KeyExpireAsync(string key, DateTimeOffset absoluteExpiration)
197+
=> _cacheClient.KeyExpireAsync(key, absoluteExpiration);
198+
199+
public Task<bool> KeyExpireAsync<T>(string key, DateTimeOffset absoluteExpiration, Action<CacheOptions>? action = null)
200+
=> _cacheClient.KeyExpireAsync<T>(key, absoluteExpiration, action);
201+
202+
public Task<bool> KeyExpireAsync(string key, CacheEntryOptions? options = null)
203+
=> _cacheClient.KeyExpireAsync(key, options);
204+
205+
public Task<bool> KeyExpireAsync<T>(string key, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
206+
=> _cacheClient.KeyExpireAsync<T>(key, options, action);
207+
208+
public Task<long> KeyExpireAsync(IEnumerable<string> keys, CacheEntryOptions? options = null)
209+
=> _cacheClient.KeyExpireAsync(keys, options);
210+
211+
public Task<long> KeyExpireAsync<T>(IEnumerable<string> keys, CacheEntryOptions? options = null, Action<CacheOptions>? action = null)
212+
=> _cacheClient.KeyExpireAsync<T>(keys, options, action);
213+
214+
public void Dispose()
215+
{
216+
//don't need to be released
217+
}
218+
}

0 commit comments

Comments
 (0)