forked from vieapps/Enyim.Caching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMemcachedClient.cs
753 lines (673 loc) · 50.5 KB
/
IMemcachedClient.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Enyim.Caching.Memcached;
using Enyim.Caching.Memcached.Results;
namespace Enyim.Caching
{
public interface IMemcachedClient : IDisposable
{
event Action<IMemcachedNode> NodeFailed;
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
/// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
bool Store(StoreMode mode, string key, object value);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
bool Store(StoreMode mode, string key, object value, TimeSpan validFor);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
bool Store(StoreMode mode, string key, object value, DateTime expiresAt);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
/// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
Task<bool> StoreAsync(StoreMode mode, string key, object value, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
Task<bool> StoreAsync(StoreMode mode, string key, object value, TimeSpan validFor, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <returns>true if the item was successfully stored in the cache; false otherwise.</returns>
Task<bool> StoreAsync(StoreMode mode, string key, object value, DateTime expiresAt, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <remarks>The item does not expire unless it is removed due memory pressure. The text protocol does not support this operation, you need to Store then GetWithCas.</remarks>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
CasResult<bool> Cas(StoreMode mode, string key, object value);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <remarks>The item does not expire unless it is removed due memory pressure.</remarks>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
CasResult<bool> Cas(StoreMode mode, string key, object value, ulong cas);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
CasResult<bool> Cas(StoreMode mode, string key, object value, DateTime expiresAt, ulong cas);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
CasResult<bool> Cas(StoreMode mode, string key, object value, TimeSpan validFor, ulong cas);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <remarks>The item does not expire unless it is removed due memory pressure. The text protocol does not support this operation, you need to Store then GetWithCas.</remarks>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
Task<CasResult<bool>> CasAsync(StoreMode mode, string key, object value, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
Task<CasResult<bool>> CasAsync(StoreMode mode, string key, object value, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
Task<CasResult<bool>> CasAsync(StoreMode mode, string key, object value, DateTime expiresAt, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location and returns its version.
/// </summary>
/// <param name="mode">Defines how the item is stored in the cache.</param>
/// <param name="key">The key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>A CasResult object containing the version of the item and the result of the operation (true if the item was successfully stored in the cache; false otherwise).</returns>
Task<CasResult<bool>> CasAsync(StoreMode mode, string key, object value, TimeSpan validFor, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="cacheMinutes"></param>
/// <returns>true if the item was successfully added in the cache; false otherwise.</returns>
bool Set(string key, object value, int cacheMinutes);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="cacheMinutes"></param>
/// <returns>true if the item was successfully added in the cache; false otherwise.</returns>
Task<bool> SetAsync(string key, object value, int cacheMinutes, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="cacheMinutes"></param>
/// <returns>true if the item was successfully added in the cache; false otherwise.</returns>
bool Add(string key, object value, int cacheMinutes);
/// <summary>
/// Inserts an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="cacheMinutes"></param>
/// <returns>true if the item was successfully added in the cache; false otherwise.</returns>
Task<bool> AddAsync(string key, object value, int cacheMinutes, CancellationToken cancellationToken = default);
/// <summary>
/// Replaces an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="cacheMinutes"></param>
/// <returns>true if the item was successfully replaced in the cache; false otherwise.</returns>
bool Replace(string key, object value, int cacheMinutes);
/// <summary>
/// Replaces an item into the cache with a cache key to reference its location.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="cacheMinutes"></param>
/// <returns>true if the item was successfully replaced in the cache; false otherwise.</returns>
Task<bool> ReplaceAsync(string key, object value, int cacheMinutes, CancellationToken cancellationToken = default);
/// <summary>
/// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
ulong Increment(string key, ulong defaultValue, ulong delta);
/// <summary>
/// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
ulong Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt);
/// <summary>
/// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
ulong Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor);
/// <summary>
/// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<ulong> IncrementAsync(string key, ulong defaultValue, ulong delta, CancellationToken cancellationToken = default);
/// <summary>
/// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<ulong> IncrementAsync(string key, ulong defaultValue, ulong delta, DateTime expiresAt, CancellationToken cancellationToken = default);
/// <summary>
/// Increments the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<ulong> IncrementAsync(string key, ulong defaultValue, ulong delta, TimeSpan validFor, CancellationToken cancellationToken = default);
/// <summary>
/// Increments the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, ulong cas);
/// <summary>
/// Increments the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas);
/// <summary>
/// Increments the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas);
/// <summary>
/// Increments the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<CasResult<ulong>> IncrementAsync(string key, ulong defaultValue, ulong delta, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Increments the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<CasResult<ulong>> IncrementAsync(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Increments the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to increase the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<CasResult<ulong>> IncrementAsync(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Decrements the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
ulong Decrement(string key, ulong defaultValue, ulong delta);
/// <summary>
/// Decrements the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
ulong Decrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt);
/// <summary>
/// Decrements the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
ulong Decrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor);
/// <summary>
/// Decrements the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<ulong> DecrementAsync(string key, ulong defaultValue, ulong delta, CancellationToken cancellationToken = default);
/// <summary>
/// Decrements the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<ulong> DecrementAsync(string key, ulong defaultValue, ulong delta, DateTime expiresAt, CancellationToken cancellationToken = default);
/// <summary>
/// Decrements the value of the specified key by the given amount. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<ulong> DecrementAsync(string key, ulong defaultValue, ulong delta, TimeSpan validFor, CancellationToken cancellationToken = default);
/// <summary>
/// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, ulong cas);
/// <summary>
/// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas);
/// <summary>
/// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
CasResult<ulong> Decrement(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas);
/// <summary>
/// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<CasResult<ulong>> DecrementAsync(string key, ulong defaultValue, ulong delta, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="expiresAt">The time when the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<CasResult<ulong>> DecrementAsync(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Decrements the value of the specified key by the given amount, but only if the item's version matches the CAS value provided. The operation is atomic and happens on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="defaultValue">The value which will be stored by the server if the specified item was not found.</param>
/// <param name="delta">The amount by which the client wants to decrease the item.</param>
/// <param name="validFor">The interval after the item is invalidated in the cache.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <returns>The new value of the item or defaultValue if the key was not found.</returns>
/// <remarks>If the client uses the Text protocol, the item must be inserted into the cache before it can be changed. It must be inserted as a <see cref="System.String"/>. Moreover the Text protocol only works with <see cref="System.UInt32"/> values, so return value -1 always indicates that the item was not found.</remarks>
Task<CasResult<ulong>> DecrementAsync(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas, CancellationToken cancellationToken = default);
/// <summary>
/// Appends the data to the end of the specified item's data on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="data">The data to be appended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
bool Append(string key, ArraySegment<byte> data);
/// <summary>
/// Appends the data to the end of the specified item's data on the server, but only if the item's version matches the CAS value provided.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <param name="data">The data to be prepended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
CasResult<bool> Append(string key, ulong cas, ArraySegment<byte> data);
/// <summary>
/// Appends the data to the end of the specified item's data on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="data">The data to be appended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
Task<bool> AppendAsync(string key, ArraySegment<byte> data, CancellationToken cancellationToken = default);
/// <summary>
/// Appends the data to the end of the specified item's data on the server, but only if the item's version matches the CAS value provided.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <param name="data">The data to be prepended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
Task<CasResult<bool>> AppendAsync(string key, ulong cas, ArraySegment<byte> data, CancellationToken cancellationToken = default);
/// <summary>
/// Inserts the data before the specified item's data on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="data">The data to be appended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
bool Prepend(string key, ArraySegment<byte> data);
/// <summary>
/// Appends the data to the end of the specified item's data on the server, but only if the item's version matches the CAS value provided.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <param name="data">The data to be prepended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
CasResult<bool> Prepend(string key, ulong cas, ArraySegment<byte> data);
/// <summary>
/// Inserts the data before the specified item's data on the server.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="data">The data to be appended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
Task<bool> PrependAsync(string key, ArraySegment<byte> data, CancellationToken cancellationToken = default);
/// <summary>
/// Appends the data to the end of the specified item's data on the server, but only if the item's version matches the CAS value provided.
/// </summary>
/// <param name="key">The key used to reference the item.</param>
/// <param name="cas">The cas value which must match the item's version.</param>
/// <param name="data">The data to be prepended to the item.</param>
/// <returns>true if the data was successfully stored; false otherwise.</returns>
Task<CasResult<bool>> PrependAsync(string key, ulong cas, ArraySegment<byte> data, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to get an item from the cache.
/// </summary>
/// <param name="key">The identifier for the item to retrieve.</param>
/// <param name="value">The retrieved item or null if not found.</param>
/// <returns>The <value>true</value> if the item was successfully retrieved.</returns>
bool TryGet(string key, out object value);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <param name="key">The identifier for the item to retrieve.</param>
/// <returns>The retrieved item, or <value>null</value> if the key was not found.</returns>
object Get(string key);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key">The identifier for the item to retrieve.</param>
/// <returns>The retrieved item, or <value>default(T)</value> if the key was not found.</returns>
T Get<T>(string key);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <param name="key">The identifier for the item to retrieve.</param>
/// <returns>The retrieved item, or <value>null</value> if the key was not found.</returns>
Task<object> GetAsync(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key">The identifier for the item to retrieve.</param>
/// <returns>The retrieved item, or <value>default(T)</value> if the key was not found.</returns>
Task<T> GetAsync<T>(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Tries to get an item from the cache with CAS.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
bool TryGetWithCas(string key, out CasResult<object> value);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
CasResult<object> GetWithCas(string key);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
CasResult<T> GetWithCas<T>(string key);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<CasResult<object>> GetWithCasAsync(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the specified item from the cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
Task<CasResult<T>> GetWithCasAsync<T>(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves multiple items from the cache.
/// </summary>
/// <param name="keys">The list of identifiers for the items to retrieve.</param>
/// <returns>a Dictionary holding all items indexed by their key.</returns>
IDictionary<string, object> Get(IEnumerable<string> keys);
/// <summary>
/// Retrieves multiple items from the cache.
/// </summary>
/// <param name="keys">The list of identifiers for the items to retrieve.</param>
/// <returns>a Dictionary holding all items indexed by their key.</returns>
Task<IDictionary<string, object>> GetAsync(IEnumerable<string> keys, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves multiple items from the cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="keys">The list of identifiers for the items to retrieve.</param>
/// <returns>a Dictionary holding all items indexed by their key.</returns>
IDictionary<string, T> Get<T>(IEnumerable<string> keys);
/// <summary>
/// Retrieves multiple items from the cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="keys">The list of identifiers for the items to retrieve.</param>
/// <returns>a Dictionary holding all items indexed by their key.</returns>
Task<IDictionary<string, T>> GetAsync<T>(IEnumerable<string> keys, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves multiple items from the cache with CAS.
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
IDictionary<string, CasResult<object>> GetWithCas(IEnumerable<string> keys);
/// <summary>
/// Retrieves multiple items from the cache with CAS.
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
Task<IDictionary<string, CasResult<object>>> GetWithCasAsync(IEnumerable<string> keys, CancellationToken cancellationToken = default);
/// <summary>
/// Removes the specified item from the cache.
/// </summary>
/// <param name="key">The identifier for the item to delete.</param>
/// <returns>true if the item was successfully removed from the cache; false otherwise.</returns>
bool Remove(string key);
/// <summary>
/// Removes the specified item from the cache.
/// </summary>
/// <param name="key">The identifier for the item to delete.</param>
/// <returns>true if the item was successfully removed from the cache; false otherwise.</returns>
Task<bool> RemoveAsync(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Determines whether an item that associated with the key is exists or not
/// </summary>
/// <param name="key">The key</param>
/// <returns>Returns a boolean value indicating if the object that associates with the key is cached or not</returns>
bool Exists(string key);
/// <summary>
/// Determines whether an item that associated with the key is exists or not
/// </summary>
/// <param name="key">The key</param>
/// <returns>Returns a boolean value indicating if the object that associates with the key is cached or not</returns>
Task<bool> ExistsAsync(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Removes all data from the cache. Note: this will invalidate all data on all servers in the pool.
/// </summary>
void FlushAll();
/// <summary>
/// Removes all data from the cache. Note: this will invalidate all data on all servers in the pool.
/// </summary>
Task FlushAllAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets statistics about the servers.
/// </summary>
/// <returns></returns>
ServerStats Stats();
/// <summary>
/// Gets statistics about the servers.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
ServerStats Stats(string type);
/// <summary>
/// Gets statistics about the servers.
/// </summary>
/// <returns></returns>
Task<ServerStats> StatsAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets statistics about the servers.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
Task<ServerStats> StatsAsync(string type, CancellationToken cancellationToken = default);
}
}
#region [ License information ]
/* ************************************************************
*
* © 2010 Attila Kiskó (aka Enyim), © 2016 CNBlogs, © 2020 VIEApps.net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion