Table of Contents

Class KeyValuePairCache

Namespace
GastroSky.Services.KeyValuePairCache
Assembly
GastroSky.dll

Thread-safe IKeyValuePairCache implementation with default cache entry lifetime of 15 minutes.

public class KeyValuePairCache : IKeyValuePairCache
Inheritance
KeyValuePairCache
Implements
Inherited Members

Properties

this[string]

Simple super-primitive (hopefully thread-safe) key-value pair cache.

public string? this[string key] { get; set; }

Parameters

key string

Property Value

string

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