Table of Contents

Interface ITaskCache

Namespace
GreenDonut
Assembly
GreenDonut.dll

A memorization cache for DataLoader.

public interface ITaskCache

Properties

Size

Gets the maximum size of the cache.

int Size { get; }

Property Value

int

Usage

Gets the count of the entries inside the cache.

int Usage { get; }

Property Value

int

Methods

Clear()

Clears the complete cache.

void Clear()

GetOrAddTask<T>(TaskCacheKey, Func<T>)

Gets a task from the cache if a task with the specified key already exists; otherwise, the createTask factory is used to create a new task and add it to the cache.

T GetOrAddTask<T>(TaskCacheKey key, Func<T> createTask) where T : Task

Parameters

key TaskCacheKey

A cache entry key.

createTask Func<T>

A factory to create the new task.

Returns

T

Returns either the retrieved or new task from the cache.

Type Parameters

T

The task type.

Exceptions

ArgumentNullException

Throws if key is null.

ArgumentNullException

Throws if createTask is null.

TryAdd<T>(TaskCacheKey, Func<T>)

Tries to add a single task to the cache. It does nothing if the task exists already.

bool TryAdd<T>(TaskCacheKey key, Func<T> createTask) where T : Task

Parameters

key TaskCacheKey

A cache entry key.

createTask Func<T>

A factory to create the new task.

Returns

bool

A value indicating whether the add was successful.

Type Parameters

T

The task type.

Exceptions

ArgumentNullException

Throws if key is null.

ArgumentNullException

Throws if createTask is null.

TryAdd<T>(TaskCacheKey, T)

Tries to add a single task to the cache. It does nothing if the task exists already.

bool TryAdd<T>(TaskCacheKey key, T value) where T : Task

Parameters

key TaskCacheKey

A cache entry key.

value T

A task.

Returns

bool

A value indicating whether the add was successful.

Type Parameters

T

The task type.

Exceptions

ArgumentNullException

Throws if key is null.

ArgumentNullException

Throws if value is null.

TryRemove(TaskCacheKey)

Removes a specific task from the cache.

bool TryRemove(TaskCacheKey key)

Parameters

key TaskCacheKey

A cache entry key.

Returns

bool

Exceptions

ArgumentNullException

Throws if key is null.