Skip to content

Commit a59a91b

Browse files
authored
fix mem cache (#278)
1 parent 2bc47a5 commit a59a91b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

BitFaster.Caching.ThroughputAnalysis/MemoryCacheAdaptor.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ public class MemoryCacheAdaptor<K, V> : ICache<K, V>
1212
{
1313
MemoryCacheOptionsAccessor accessor;
1414
MemoryCache exMemoryCache;
15+
CachePolicy policy;
1516

1617
public MemoryCacheAdaptor(int capacity)
1718
{
1819
accessor = new MemoryCacheOptionsAccessor();
1920
accessor.Value.SizeLimit = capacity;
2021

2122
exMemoryCache = new MemoryCache(accessor);
23+
policy = new CachePolicy(new Optional<IBoundedPolicy>(new BoundedPolicy(capacity)), Optional<ITimePolicy>.None());
2224
}
2325

2426
public int Count => throw new NotImplementedException();
@@ -27,7 +29,7 @@ public MemoryCacheAdaptor(int capacity)
2729

2830
public Optional<ICacheEvents<K, V>> Events => throw new NotImplementedException();
2931

30-
public CachePolicy Policy => throw new NotImplementedException();
32+
public CachePolicy Policy => this.policy;
3133

3234
public ICollection<K> Keys => throw new NotImplementedException();
3335

@@ -81,6 +83,23 @@ IEnumerator IEnumerable.GetEnumerator()
8183
{
8284
throw new NotImplementedException();
8385
}
86+
87+
private class BoundedPolicy : IBoundedPolicy
88+
{
89+
private int capacity;
90+
91+
public BoundedPolicy(int capacity)
92+
{
93+
this.capacity = capacity;
94+
}
95+
96+
public int Capacity => this.capacity;
97+
98+
public void Trim(int itemCount)
99+
{
100+
throw new NotImplementedException();
101+
}
102+
}
84103
}
85104

86105
public class MemoryCacheOptionsAccessor

0 commit comments

Comments
 (0)