Files
mixtape/zero.Core/Collections/CollectionCache.cs
T

39 lines
687 B
C#
Raw Normal View History

2021-11-23 16:09:01 +01:00
using System.Collections.Concurrent;
namespace zero.Collections;
public class CollectionCache : ICollectionCache
{
protected ConcurrentDictionary<string, object> _cache = new();
public CollectionCache()
{
}
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;
}
public ICollectionCache For(CachableEntityCollectionOptions options)
{
return this;
}
}
public interface ICollectionCache
{
ICollectionCache For(CachableEntityCollectionOptions options);
bool TryGetValue<T>(string id, out T model);
}