Skip to content

Commit fa1c0fb

Browse files
authored
Add TLFU factory (#584)
1 parent 3292910 commit fa1c0fb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

BitFaster.Caching.ThroughputAnalysis/CacheFactory.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
using System;
23
using System.Collections.Generic;
34
using System.Data;
45
using BitFaster.Caching.Lfu;
@@ -105,6 +106,35 @@ public ConcurrentLfuFactory(int capacity)
105106
}
106107
}
107108

109+
public class ConcurrentTLfuFactory : ICacheFactory
110+
{
111+
private readonly int capacity;
112+
113+
public ConcurrentTLfuFactory(int capacity)
114+
{
115+
this.capacity = capacity;
116+
}
117+
118+
public string Name => "ConcurrentTLfu";
119+
120+
public DataRow DataRow { get; set; }
121+
122+
public (IScheduler, ICache<long, int>) Create(int threadCount)
123+
{
124+
var scheduler = new BackgroundThreadScheduler();
125+
126+
var cache = new ConcurrentLfuBuilder<long, int>()
127+
.WithCapacity(capacity)
128+
.WithScheduler(scheduler)
129+
.WithConcurrencyLevel(threadCount)
130+
.WithKeyComparer(EqualityComparer<long>.Default)
131+
.WithExpireAfterWrite(TimeSpan.FromHours(1))
132+
.Build();
133+
134+
return (scheduler, cache);
135+
}
136+
}
137+
108138
public class ClassicLruFactory : ICacheFactory
109139
{
110140
private readonly int capacity;

0 commit comments

Comments
 (0)