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
TKeyTValue
Properties
Count
Gets the number of items currently in the cache.
int Count { get; }
Property Value
EvictionPolicy
Gets or sets the eviction policy for the cache.
CacheEvictionPolicy EvictionPolicy { get; set; }
Property Value
IsReadOnly
Gets or sets a value indicating whether the cache is read-only.
bool IsReadOnly { get; }
Property Value
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
Metrics
Gets cache performance metrics.
CacheMetrics Metrics { get; }
Property Value
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
keyTKeyThe 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
keyTKeyThe cache key
factoryFunc<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
keyTKeyThe cache key
factoryFunc<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
keyTKeyThe 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
keyTKeyThe cache key
valueTValueThe value to cache
TryGetValue(TKey, out TValue)
Attempts to get a value from the cache.
bool TryGetValue(TKey key, out TValue value)
Parameters
keyTKeyThe cache key
valueTValueThe cached value if found
Returns
- bool
True if the value was found, false otherwise