Updated audio image extraction logic. Added caching classes.

This commit is contained in:
2025-02-26 19:07:29 -05:00
parent b38e4dc858
commit dfdf514fe2
11 changed files with 259 additions and 14 deletions

View File

@@ -0,0 +1,40 @@
namespace Harmonia.Core.Caching;
public abstract class Cache<TKey, TValue> : ICache<TKey, TValue> where TKey : notnull
{
protected abstract TValue? TryGetValue(object key);
protected abstract TValue? Fetch(TKey key);
protected abstract void AddToCache(object key, TValue value);
public TValue? Get(TKey key)
{
object? actualKey = GetKey(key);
if (actualKey == null)
return default;
return TryGetValue(actualKey) ?? Refresh(key);
}
public TValue? Refresh(TKey key)
{
object? actualKey = GetKey(key);
if (actualKey == null)
return default;
TValue? value = Fetch(key);
if (value == null)
return default;
AddToCache(actualKey, value);
return value;
}
protected virtual object? GetKey(TKey key)
{
return key;
}
}