Table of Contents

Interface ICache<TKey, TValue>

Namespace
MoonBark.GridPlacement.Core.Interfaces
Assembly
MoonBark.GridPlacement.Core.dll

Generic cache interface for Core components. Provides unified caching functionality with dependency injection support.

public interface ICache<TKey, TValue>

Type Parameters

TKey
TValue

Properties

Count

Gets the number of items currently in the cache.

int Count { get; }

Property Value

int

EvictionPolicy

Gets or sets the eviction policy for the cache.

CacheEvictionPolicy EvictionPolicy { get; set; }

Property Value

CacheEvictionPolicy

IsReadOnly

Gets or sets a value indicating whether the cache is read-only.

bool IsReadOnly { get; }

Property Value

bool

MaxSize

Gets or sets the maximum number of items the cache can hold. When exceeded, items will be evicted based on the eviction policy.

int MaxSize { get; set; }

Property Value

int

Metrics

Gets cache performance metrics.

CacheMetrics Metrics { get; }

Property Value

CacheMetrics

Methods

Clear()

Clears all items from the cache.

void Clear()

ContainsKey(TKey)

Checks if the cache contains the specified key.

bool ContainsKey(TKey key)

Parameters

key TKey

The cache key

Returns

bool

True if the key exists, false otherwise

GetKeys()

Gets all keys currently in the cache.

IEnumerable<TKey> GetKeys()

Returns

IEnumerable<TKey>

Collection of cache keys

GetOrAdd(TKey, Func<TKey, TValue>)

Gets a value from the cache, or creates it if it doesn't exist.

TValue GetOrAdd(TKey key, Func<TKey, TValue> factory)

Parameters

key TKey

The cache key

factory Func<TKey, TValue>

Function to create the value if not cached

Returns

TValue

The cached or newly created value

GetOrAdd(TKey, Func<TValue>)

Gets a value from the cache, or creates it if it doesn't exist.

TValue GetOrAdd(TKey key, Func<TValue> factory)

Parameters

key TKey

The cache key

factory Func<TValue>

Function to create the value if not cached

Returns

TValue

The cached or newly created value

GetValues()

Gets all values currently in the cache.

IEnumerable<TValue> GetValues()

Returns

IEnumerable<TValue>

Collection of cache values

Remove(TKey)

Removes a value from the cache.

bool Remove(TKey key)

Parameters

key TKey

The cache key

Returns

bool

True if the value was removed, false if not found

Set(TKey, TValue)

Adds or updates a value in the cache.

void Set(TKey key, TValue value)

Parameters

key TKey

The cache key

value TValue

The value to cache

TryGetValue(TKey, out TValue)

Attempts to get a value from the cache.

bool TryGetValue(TKey key, out TValue value)

Parameters

key TKey

The cache key

value TValue

The cached value if found

Returns

bool

True if the value was found, false otherwise