-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathIDistributedCacheClient.cs
271 lines (232 loc) · 13.7 KB
/
IDistributedCacheClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
namespace Masa.BuildingBlocks.Caching;
public interface IDistributedCacheClient : ICacheClient
{
T? GetOrSet<T>(string key, Func<CacheEntry<T>> setter, Action<CacheOptions>? action = null);
Task<T?> GetOrSetAsync<T>(string key, Func<CacheEntry<T>> setter, Action<CacheOptions>? action = null);
/// <summary>
/// Flush cache time to live
/// </summary>
/// <param name="keys"></param>
void Refresh(params string[] keys);
/// <summary>
/// Flush cache time to live
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
Task RefreshAsync(params string[] keys);
/// <summary>
/// Flush cache time to live
/// </summary>
/// <param name="keys">A collection of cache keys</param>
void Remove(params string[] keys);
/// <summary>
/// Remove cache key
/// </summary>
/// <param name="keys">A collection of cache keys</param>
/// <returns></returns>
Task RemoveAsync(params string[] keys);
/// <summary>
/// Get whether the cache key exists
/// </summary>
/// <param name="key">Complete cache key, cache key is no longer formatted</param>
/// <returns></returns>
bool Exists(string key);
/// <summary>
/// Get whether the cache key exists
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
bool Exists<T>(string key, Action<CacheOptions>? action = null);
/// <summary>
/// Get whether the cache key exists
/// </summary>
/// <param name="key">Complete cache key, cache key is no longer formatted</param>
/// <returns></returns>
Task<bool> ExistsAsync(string key);
/// <summary>
/// Get whether the cache key exists
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
Task<bool> ExistsAsync<T>(string key, Action<CacheOptions>? action = null);
/// <summary>
/// Only get the key, do not trigger the update expiration time policy
/// </summary>
/// <param name="keyPattern">Complete keyPattern, no longer formatted, such as: app_*</param>
/// <returns></returns>
IEnumerable<string> GetKeys(string keyPattern);
/// <summary>
/// The set of cached keys that match the rules according to the key fuzzy matching
/// Obtain the set of keys that meet the rules according to the obtained type and KeyPattern
/// </summary>
/// <param name="keyPattern">keyPattern, used to change the global cache configuration information, eg: 1*</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
IEnumerable<string> GetKeys<T>(string keyPattern, Action<CacheOptions>? action = null);
/// <summary>
/// Only get the key, do not trigger the update expiration time policy
/// </summary>
/// <param name="keyPattern">Complete keyPattern, no longer formatted, such as: app_*</param>
/// <returns></returns>
Task<IEnumerable<string>> GetKeysAsync(string keyPattern);
/// <summary>
/// The set of cached keys that match the rules according to the key fuzzy matching
/// Obtain the set of keys that meet the rules according to the obtained type and KeyPattern
/// </summary>
/// <param name="keyPattern">keyPattern, used to change the global cache configuration information, eg: 1*</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
Task<IEnumerable<string>> GetKeysAsync<T>(string keyPattern, Action<CacheOptions>? action = null);
IEnumerable<KeyValuePair<string, T?>> GetByKeyPattern<T>(string keyPattern, Action<CacheOptions>? action = null);
Task<IEnumerable<KeyValuePair<string, T?>>> GetByKeyPatternAsync<T>(string keyPattern, Action<CacheOptions>? action = null);
void Publish(string channel, Action<PublishOptions> options);
Task PublishAsync(string channel, Action<PublishOptions> options);
void Subscribe<T>(string channel, Action<SubscribeOptions<T>> options);
Task SubscribeAsync<T>(string channel, Action<SubscribeOptions<T>> options);
/// <summary>
/// Increment Hash
/// </summary>
/// <param name="key">cache key</param>
/// <param name="value">incremental increment, must be greater than 0</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
Task<long> HashIncrementAsync(string key, long value = 1L, Action<CacheOptions>? action = null);
/// <summary>
/// Descending Hash
/// </summary>
/// <param name="key">cache key</param>
/// <param name="value">decrement increment, must be greater than 0</param>
/// <param name="defaultMinVal">critical value, must be greater than or equal to 0</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
Task<long> HashDecrementAsync(string key, long value = 1L, long defaultMinVal = 0L, Action<CacheOptions>? action = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Complete cache key</param>
/// <param name="absoluteExpirationRelativeToNow">absolute Expiration Relative To Now,Permanently valid when null</param>
/// <returns></returns>
bool KeyExpire(string key, TimeSpan? absoluteExpirationRelativeToNow);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="absoluteExpirationRelativeToNow">absolute Expiration Relative To Now,Permanently valid when null</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
bool KeyExpire<T>(string key, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Complete cache key</param>
/// <param name="absoluteExpiration">absolute Expiration,Permanently valid when null</param>
/// <returns></returns>
bool KeyExpire(string key, DateTimeOffset absoluteExpiration);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="absoluteExpiration">absolute Expiration,Permanently valid when null</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
bool KeyExpire<T>(string key, DateTimeOffset absoluteExpiration, Action<CacheOptions>? action = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Complete cache key</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <returns></returns>
bool KeyExpire(string key, CacheEntryOptions? options = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
bool KeyExpire<T>(string key, CacheEntryOptions? options = null, Action<CacheOptions>? action = null);
/// <summary>
/// Refresh the lifetime of the cache key set
/// </summary>
/// <param name="keys">A collection of cache keys</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <returns>Get the number of caches that have successfully refreshed the cache key life cycle</returns>
long KeyExpire(IEnumerable<string> keys, CacheEntryOptions? options = null);
/// <summary>
/// Refresh the lifetime of the cache key set
/// </summary>
/// <param name="keys">A collection of cache keys, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <typeparam name="T"></typeparam>
/// <returns>Get the number of caches that have successfully refreshed the cache key life cycle</returns>
long KeyExpire<T>(IEnumerable<string> keys, CacheEntryOptions? options = null, Action<CacheOptions>? action = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Complete cache key</param>
/// <param name="absoluteExpirationRelativeToNow">absolute Expiration Relative To Now,Permanently valid when null</param>
/// <returns></returns>
Task<bool> KeyExpireAsync(string key, TimeSpan? absoluteExpirationRelativeToNow);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="absoluteExpirationRelativeToNow">absolute Expiration Relative To Now,Permanently valid when null</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
Task<bool> KeyExpireAsync<T>(string key, TimeSpan? absoluteExpirationRelativeToNow, Action<CacheOptions>? action = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Complete cache key</param>
/// <param name="absoluteExpiration">absolute Expiration,Permanently valid when null</param>
/// <returns></returns>
Task<bool> KeyExpireAsync(string key, DateTimeOffset absoluteExpiration);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="absoluteExpiration">absolute Expiration,Permanently valid when null</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
Task<bool> KeyExpireAsync<T>(string key, DateTimeOffset absoluteExpiration, Action<CacheOptions>? action = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Complete cache key</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <returns></returns>
Task<bool> KeyExpireAsync(string key, CacheEntryOptions? options = null);
/// <summary>
/// Set cache lifetime
/// </summary>
/// <param name="key">Cache key, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
Task<bool> KeyExpireAsync<T>(string key, CacheEntryOptions? options = null, Action<CacheOptions>? action = null);
/// <summary>
/// Batch setting cache lifetime
/// </summary>
/// <param name="keys">A collection of cache keys</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <returns></returns>
Task<long> KeyExpireAsync(IEnumerable<string> keys, CacheEntryOptions? options = null);
/// <summary>
/// Batch setting cache lifetime
/// </summary>
/// <param name="keys">A collection of cache keys, the actual cache key will decide whether to format the cache key according to the global configuration and Action</param>
/// <param name="options">Configure the cache life cycle, which is consistent with the default configuration when it is empty</param>
/// <param name="action">Cache configuration, used to change the global cache configuration information</param>
/// <returns></returns>
Task<long> KeyExpireAsync<T>(IEnumerable<string> keys, CacheEntryOptions? options = null, Action<CacheOptions>? action = null);
}