Class KeyValuePairCacheValkey
- Namespace
- GastroSky.Services.KeyValuePairCache
- Assembly
- GastroSky.dll
IKeyValuePairCache implementation that makes use of a local Valkey instance, with default cache entry lifetime of 15 minutes.
public class KeyValuePairCacheValkey : IKeyValuePairCache
- Inheritance
-
KeyValuePairCacheValkey
- Implements
- Inherited Members
Constructors
KeyValuePairCacheValkey(IConnectionMultiplexer)
IKeyValuePairCache implementation that makes use of a local Valkey instance, with default cache entry lifetime of 15 minutes.
public KeyValuePairCacheValkey(IConnectionMultiplexer valkey)
Parameters
valkeyIConnectionMultiplexer
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!
public string? this[string key] { get; set; }
Parameters
Property Value
Methods
ClearAsync()
Clears the cache of all of its key-value pairs!
public 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)!
public 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!
public Task<string?> GetStringAsync(string key)
Parameters
Returns
RemoveAsync(string)
Removes a given entry from the cache.
public 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!
public 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.
public 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).