From d44dbb969603bec6d2989b875798ecaf83185467 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Tue, 27 Sep 2022 22:40:00 -0700 Subject: [PATCH] fix mem cache --- .../MemoryCacheAdaptor.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/BitFaster.Caching.ThroughputAnalysis/MemoryCacheAdaptor.cs b/BitFaster.Caching.ThroughputAnalysis/MemoryCacheAdaptor.cs index ca0802a9..887e6787 100644 --- a/BitFaster.Caching.ThroughputAnalysis/MemoryCacheAdaptor.cs +++ b/BitFaster.Caching.ThroughputAnalysis/MemoryCacheAdaptor.cs @@ -12,6 +12,7 @@ public class MemoryCacheAdaptor : ICache { MemoryCacheOptionsAccessor accessor; MemoryCache exMemoryCache; + CachePolicy policy; public MemoryCacheAdaptor(int capacity) { @@ -19,6 +20,7 @@ public MemoryCacheAdaptor(int capacity) accessor.Value.SizeLimit = capacity; exMemoryCache = new MemoryCache(accessor); + policy = new CachePolicy(new Optional(new BoundedPolicy(capacity)), Optional.None()); } public int Count => throw new NotImplementedException(); @@ -27,7 +29,7 @@ public MemoryCacheAdaptor(int capacity) public Optional> Events => throw new NotImplementedException(); - public CachePolicy Policy => throw new NotImplementedException(); + public CachePolicy Policy => this.policy; public ICollection Keys => throw new NotImplementedException(); @@ -81,6 +83,23 @@ IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); } + + private class BoundedPolicy : IBoundedPolicy + { + private int capacity; + + public BoundedPolicy(int capacity) + { + this.capacity = capacity; + } + + public int Capacity => this.capacity; + + public void Trim(int itemCount) + { + throw new NotImplementedException(); + } + } } public class MemoryCacheOptionsAccessor