Table of Contents

Class BuildCache<T>

Namespace
Invex.Atom.Workflows
Assembly
Invex.Atom.Workflows.dll

Represents a cache scoped to a build, using an IBuildAccessor as the key.

public sealed class BuildCache<T>

Type Parameters

T

The type of the items to be stored in the cache.

Inheritance
object
BuildCache<T>

Remarks

Keys are compared by their default equality, which for build definitions and helpers is reference equality. The cache is thread-safe and holds its entries for the lifetime of the cache instance, so typically it is stored in a static readonly field.

Typical use is to compute an expensive per-build value once, e.g. via GetOrAdd(IBuildAccessor, Func<IBuildAccessor, T>).

Constructors

BuildCache()

public BuildCache()

Methods

Clear()

Removes all keys and values from the cache.

public void Clear()

GetOrAdd(IBuildAccessor, Func<IBuildAccessor, T>)

Gets the value associated with the specified key, or adds one created by valueFactory if the key is not present.

public T GetOrAdd(IBuildAccessor key, Func<IBuildAccessor, T> valueFactory)

Parameters

key IBuildAccessor

The key of the value to get or add.

valueFactory Func<IBuildAccessor, T>

The function used to create the value when the key is not present.

Returns

T

The existing or newly created value.

Remarks

Under concurrent access valueFactory may be invoked more than once for the same key, but only one result is stored and returned to all callers.

Remove(IBuildAccessor)

Removes the value associated with the specified key from the cache.

public bool Remove(IBuildAccessor key)

Parameters

key IBuildAccessor

The key of the value to remove.

Returns

bool

true if the key was found and removed; otherwise, false.

Set(IBuildAccessor, T)

Adds or updates a value in the cache with the provided key.

public T Set(IBuildAccessor key, T value)

Parameters

key IBuildAccessor

The key of the value to set.

value T

The value to associate with the key.

Returns

T

The value that was set.

TryGetValue(IBuildAccessor, out T)

Attempts to get the value associated with the specified key from the cache.

public bool TryGetValue(IBuildAccessor key, out T result)

Parameters

key IBuildAccessor

The key of the value to get.

result T

When this method returns, contains the object from the cache that has the specified key, or the default value of the type if the operation failed.

Returns

bool

true if the key was found in the cache; otherwise, false.