2021-11-23 16:09:01 +01:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
namespace zero.Stores;
|
2021-11-23 16:09:01 +01:00
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public class StoreCache : IStoreCache
|
2021-11-23 16:09:01 +01:00
|
|
|
{
|
|
|
|
|
protected ConcurrentDictionary<string, object> _cache = new();
|
|
|
|
|
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public StoreCache()
|
2021-11-23 16:09:01 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryGetValue<T>(string id, out T model)
|
|
|
|
|
{
|
|
|
|
|
if (_cache.TryGetValue(id, out object modelObj))
|
|
|
|
|
{
|
|
|
|
|
model = (T)modelObj;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 13:56:08 +01:00
|
|
|
//public IStoreCache For(CachableEntityStoreOptions options)
|
|
|
|
|
//{
|
|
|
|
|
// return this;
|
|
|
|
|
//}
|
2021-11-23 16:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public interface IStoreCache
|
2021-11-23 16:09:01 +01:00
|
|
|
{
|
2021-11-24 13:56:08 +01:00
|
|
|
//IStoreCache For(CachableEntityStoreOptions options);
|
2021-11-23 16:09:01 +01:00
|
|
|
|
|
|
|
|
bool TryGetValue<T>(string id, out T model);
|
|
|
|
|
}
|