2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
25 this.dictionary = Dictionary;
26 this.cache =
new Cache<string, Rec>(CacheSize, TimeSpan.MaxValue, TimeSpan.MaxValue,
true);
27 this.cache.Removed += this.Cache_Removed;
57 await this.dictionary.RemoveAsync(e.
Key);
73 await this.dictionary.AddAsync(e.
Key, e.
Value.Value,
true);
96 public object this[
string key]
100 if (this.cache.TryGetValue(key, out
Rec Rec))
103 if (this.dictionary.TryGetValue(key, out
object Value))
105 this.cache[key] =
new Rec()
114 throw new KeyNotFoundException(
"key not found in dictionary: " + key);
119 this.cache[key] =
new Rec()
130 public ICollection<string>
Keys
135 return this.dictionary.Keys;
147 return this.dictionary.Values;
159 return this.dictionary.Count;
171 public void Add(
string key,
object value)
173 this.cache[key] =
new Rec()
183 public void Add(KeyValuePair<string, object> item)
185 this.cache[item.Key] =
new Rec()
198 this.dictionary.Clear();
204 public bool Contains(KeyValuePair<string, object> item)
206 if (this.cache.TryGetValue(item.Key, out
Rec Rec))
207 return Rec.
Value.Equals(item.Value);
208 else if (this.dictionary.TryGetValue(item.Key, out
object Value))
209 return Value.Equals(item.Value);
219 return this.cache.ContainsKey(key) || this.dictionary.ContainsKey(key);
225 public void CopyTo(KeyValuePair<string, object>[] array,
int arrayIndex)
228 this.dictionary.CopyTo(array, arrayIndex);
237 return this.dictionary.GetEnumerator();
246 return this.dictionary.GetEnumerator();
254 if (this.cache.TryGetValue(key, out
Rec Rec))
256 this.cache.Remove(key);
259 return this.dictionary.Remove(key);
264 return this.dictionary.Remove(key);
270 public bool Remove(KeyValuePair<string, object> item)
272 if (this.cache.TryGetValue(item.Key, out
Rec Rec))
277 this.cache.Remove(item.Key);
280 return this.dictionary.Remove(item.Key);
284 else if (this.dictionary.TryGetValue(item.Key, out
object Value))
286 if (Value.Equals(item.Value))
287 return this.dictionary.Remove(item.Key);
290 this.cache[item.Key] =
new Rec()
308 if (this.cache.TryGetValue(key, out
Rec Rec))
313 else if (this.dictionary.TryGetValue(key, out value))
315 this.cache[key] =
new Rec()
327 IEnumerator IEnumerable.GetEnumerator()
330 return this.dictionary.GetEnumerator();
340 KeyValuePair<string, Rec>[] Records = this.cache.ToArray();
351 foreach (KeyValuePair<string, Rec>
Rec in Records)
355 await this.dictionary.AddAsync(
Rec.Key,
Rec.
Value.Value,
true);
388 KeyValuePair<string, Rec>[] Records = this.cache.ToArray();
391 foreach (KeyValuePair<string, Rec>
Rec in Records)
394 await this.dictionary.AddAsync(
Rec.Key,
Rec.
Value.Value,
true);
404 this.cache.Dispose();
405 this.dictionary.Dispose();
414 this.dictionary.DeleteAndDispose();
423 return this.dictionary.ClearAsync();
431 return this.cache.ContainsKey(key) || await this.dictionary.ContainsKeyAsync(key);
439 this.
Add(key, value);
440 return Task.CompletedTask;
446 public Task
AddAsync(
string key,
object value,
bool ReplaceIfExists)
451 this.
Add(key, value);
453 return Task.CompletedTask;
461 if (this.cache.TryGetValue(key, out
Rec Rec))
463 this.cache.Remove(key);
466 return await this.dictionary.RemoveAsync(key);
471 return await this.dictionary.RemoveAsync(key);
479 if (this.cache.TryGetValue(key, out
Rec Rec))
480 return new KeyValuePair<bool, object>(
true,
Rec.
Value);
483 KeyValuePair<bool, object> P = await this.dictionary.TryGetValueAsync(key);
487 this.cache[key] =
new Rec()
504 public async Task<KeyValuePair<string, object>[]>
GetEntriesAsync(
string FromKey,
string ToKey)
506 Dictionary<string, object> ByName =
new Dictionary<string, object>();
508 foreach (KeyValuePair<string, object>
Entry in await this.dictionary.GetEntriesAsync(FromKey, ToKey))
511 foreach (KeyValuePair<string, Rec>
Entry in this.cache.ToArray())
514 KeyValuePair<string, object>[] Result =
new KeyValuePair<string, object>[ByName.Count];
516 foreach (KeyValuePair<string, object>
Entry in ByName)
529 return this.dictionary.CopyKeysToAsync(
Keys, Offset);
539 return this.dictionary.CopyValuesToAsync(
Values, Offset);
548 return this.dictionary.GetKeysAsync();
557 return this.dictionary.GetValuesAsync();
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task EndBulk()
Ends bulk-processing of data. Must be called once for every call to StartBulk.
static Task StartBulk()
Starts bulk-proccessing of data. Must be followed by a call to EndBulk.
Optimizes a persistent IPersistentDictionary using a cache.
void DeleteAndDispose()
TODO
Task CopyValuesToAsync(object[] Values, int Offset)
Copies available values to an array.
bool Remove(string key)
TODO
async Task< KeyValuePair< bool, object > > TryGetValueAsync(string key)
TODO
CachedStringDictionary(int CacheSize, IPersistentDictionary Dictionary)
Optimizes a persistent IPersistentDictionary using a cache.
bool Contains(KeyValuePair< string, object > item)
TODO
Task AddAsync(string key, object value)
TODO
Task< object[]> GetValuesAsync()
Gets all values.
void Add(KeyValuePair< string, object > item)
TODO
void CopyTo(KeyValuePair< string, object >[] array, int arrayIndex)
TODO
async Task< KeyValuePair< string, object >[]> GetEntriesAsync(string FromKey, string ToKey)
Gets a range of entries from one key to another.
IEnumerator< KeyValuePair< string, object > > GetEnumerator()
TODO
Task CopyKeysToAsync(string[] Keys, int Offset)
Copies available keys to a string array.
async Task FlushAsync()
TODO
ICollection< string > Keys
TODO
ICollection< object > Values
TODO
bool ContainsKey(string key)
TODO
Task< string[]> GetKeysAsync()
Gets all keys.
async Task< bool > ContainsKeyAsync(string key)
TODO
Task AddAsync(string key, object value, bool ReplaceIfExists)
TODO
bool TryGetValue(string key, out object value)
TODO
async Task< bool > RemoveAsync(string key)
TODO
async Task< IEnumerator< KeyValuePair< string, object > > > GetEnumeratorAsync()
TODO
bool Remove(KeyValuePair< string, object > item)
TODO
void Add(string key, object value)
TODO
Represents an entry in a block or bucket file.
Implements an in-memory cache.
Event arguments for cache item removal events.
KeyType Key
Key of item that was removed.
ValueType Value
Value of item that was removed.
RemovedReason Reason
Reason for removing the item.
Persistent dictionary that can contain more entries than possible in the internal memory.
RemovedReason
Reason for removing the item.