Interface IKeyValuePairCache
- Namespace
- GastroSky.Services.KeyValuePairCache
- Assembly
- GastroSky.dll
Simple super-primitive (hopefully thread-safe) key-value pair cache.
public interface IKeyValuePairCache
Properties
this[string]
Cache indexer that gets or sets a value via a lookup key string.
When setting a value, the default lifetime will be used (which implementations may define freely on their own).
If the key does not exist or has expired,
null will be returned!
string? this[string key] { get; set; }
Parameters
Property Value
Methods
ClearAsync()
Clears the cache of all of its key-value pairs!
Task ClearAsync()
Returns
GetAsync<T>(string)
Gets an arbitrary type from the cache. This will most probably perform some sort of deserialization!
If the key does not exist or has expired,
default(T) will be returned (which could mean null)!
Task<T?> GetAsync<T>(string key)
Parameters
Returns
- Task<T>
The found object (if nothing was found,
default(T)will be returned, which could benull)
Type Parameters
TThe type of object stored in the cache.
GetStringAsync(string)
Attempts to retrieve a string value from the cache via its lookup key.
If the key does not exist or has expired,
null will be returned!
Task<string?> GetStringAsync(string key)
Parameters
Returns
RemoveAsync(string)
Removes a given entry from the cache.
Task RemoveAsync(string key)
Parameters
keystringLookup key.
Returns
SetAsync<T>(string, T, TimeSpan?)
Stores a given object of type T under a key string with an optionally customizable lifetime after which the cache entry will be discarded.
This will most probably perform some sort of serialization!
Task SetAsync<T>(string key, T value, TimeSpan? lifetime = null)
Parameters
keystringLookup key string.
valueTObject to store in the cache.
lifetimeTimeSpan?[OPTIONAL] The lifetime of the cache entry (leave out by passing
nullif you want the implementation to decide the expiration time).
Returns
Type Parameters
TType of object to store in the cache.
SetStringAsync(string, string, TimeSpan?)
Stores a given string value under a key with an optionally customizable lifetime after which the cache entry will be discarded.
Task SetStringAsync(string key, string value, TimeSpan? lifetime = null)
Parameters
keystringLookup key string.
valuestringValue string to store.
lifetimeTimeSpan?[OPTIONAL] The lifetime of the cache entry (leave out by passing
nullif you want the implementation to decide the expiration time).