2023-08-12 19:08:38 +01:00
|
|
|
|
namespace LootDumpProcessor.Storage.Implementations.Memory;
|
|
|
|
|
|
|
|
|
|
public class MemoryDataStorage : IDataStorage
|
|
|
|
|
{
|
2024-01-30 14:54:01 +00:00
|
|
|
|
private static readonly Dictionary<string, object> CachedObjects = new();
|
|
|
|
|
private static readonly object _cacheObjectLock = new();
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|