Table of Contents

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

valkey IConnectionMultiplexer

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

key string

The index key string under which the desired value should be retrieved/stored.

Property Value

string

The found string value (null if nothing was found).

Methods

ClearAsync()

Clears the cache of all of its key-value pairs!

public Task ClearAsync()

Returns

Task

Task

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

key string

Lookup key string.

Returns

Task<T>

The found object (if nothing was found, default(T) will be returned, which could be null)

Type Parameters

T

The 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

key string

The index key string under which the desired value should be retrieved/stored.

Returns

Task<string>

The found string value (if nothing was found, null is returned).

RemoveAsync(string)

Removes a given entry from the cache.

public Task RemoveAsync(string key)

Parameters

key string

Lookup key.

Returns

Task

Task

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

key string

Lookup key string.

value T

Object to store in the cache.

lifetime TimeSpan?

[OPTIONAL] The lifetime of the cache entry (leave out by passing null if you want the implementation to decide the expiration time).

Returns

Task

Task

Type Parameters

T

Type 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

key string

Lookup key string.

value string

Value string to store.

lifetime TimeSpan?

[OPTIONAL] The lifetime of the cache entry (leave out by passing null if you want the implementation to decide the expiration time).

Returns

Task

Task