50 lines
1.1 KiB
C#
Raw Normal View History

2023-08-12 19:08:38 +01:00
namespace LootDumpProcessor.Storage.Implementations.Memory;
public class MemoryDataStorage : IDataStorage
{
private static readonly Dictionary<string, object> CachedObjects = new Dictionary<string, object>();
private static readonly object _cacheObjectLock = new object();
public void Setup()
{
}
public void Store<T>(T t) where T : IKeyable
{
lock (_cacheObjectLock)
{
CachedObjects.Add(GetLookupKey(t.GetKey()), t);
}
}
public bool Exists(IKey t)
{
lock (_cacheObjectLock)
{
return CachedObjects.ContainsKey(GetLookupKey(t));
}
}
public T? GetItem<T>(IKey key) where T : IKeyable
{
lock (_cacheObjectLock)
{
if (CachedObjects.TryGetValue(GetLookupKey(key), out var value))
{
return (T)value;
}
}
return default;
}
public List<T> GetAll<T>()
{
throw new NotImplementedException();
}
private string GetLookupKey(IKey key)
{
return string.Join("-", key.GetLookupIndex());
}
}