2using System.Threading.Tasks;
16 private static readonly
object synchObject =
new object();
18 private class CounterRec
20 public TaskCompletionSource<bool> Stored =
new TaskCompletionSource<bool>();
29 counters.Removed += Counters_Removed;
40 e.
Value.Stored.TrySetResult(
true);
45 if (e.
Value.Counter.Counter == 0)
47 if (!
string.IsNullOrEmpty(e.
Value.Counter.ObjectId))
52 if (
string.IsNullOrEmpty(e.
Value.Counter.ObjectId))
58 e.
Value.Stored.TrySetResult(
true);
62 e.
Value.Stored.TrySetResult(
false);
71 CounterRec[] Records = counters.GetValues();
74 foreach (CounterRec Rec
in Records)
75 await Rec.Stored.Task;
98 if (counters.TryGetValue(Key, out CounterRec Rec))
100 Rec.Counter.Counter += Delta;
103 return Rec.Counter.Counter;
111 if (counters.TryGetValue(Key, out CounterRec Rec))
113 Rec.Counter.Counter += Delta;
128 counters[Key] =
new CounterRec()
136 Counter.Counter += Delta;
137 counters[Key] =
new CounterRec()
181 if (counters.TryGetValue(Key, out CounterRec Rec))
182 return Rec.Counter.Counter;
189 if (counters.TryGetValue(Key, out CounterRec Rec))
201 counters[Key] =
new CounterRec()
209 counters[Key] =
new CounterRec()
Represents a case-insensitive string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
static async Task Delete(object Object)
Deletes an object in the database.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
This filter selects objects that have a named field equal to a given value.
Implements an in-memory cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
Contains a runtime counter.
Static class managing persistent counters.
static Task< long > DecrementCounter(CaseInsensitiveString Key, long Delta)
Decrements a counter.
static Task< long > IncrementCounter(CaseInsensitiveString Key)
Increments a counter.
static async Task< long > IncrementCounter(CaseInsensitiveString Key, long Delta)
Increments a counter.
static Task< long > DecrementCounter(CaseInsensitiveString Key)
Decrements a counter.
static async Task FlushAsync()
Flushes all cached counters to the database.
static async Task< long > GetCount(CaseInsensitiveString Key)
Gets the current count of a counter.