BitFaster.Caching 2.4.1
⚡ BitFaster.Caching
High performance, thread-safe in-memory caching primitives for .NET.
ConcurrentLru
ConcurrentLru is a light weight drop in replacement for ConcurrentDictionary, but with bounded size enforced by the TU-Q eviction policy (based on 2Q). There are no background threads, no global locks, concurrent throughput is high, lookups are fast and hit rate outperforms a pure LRU in all tested scenarios.
Choose a capacity and use just like ConcurrentDictionary, but with bounded size:
int capacity = 128;
var lru = new ConcurrentLru<string, SomeItem>(capacity);
var value = lru.GetOrAdd("key", (key) => new SomeItem(key));
Optionally configure ConcurrentLru with a time-based eviction policy, either:
- Expire after write
- Expire after access
- Calculate an expiry time per item
ConcurrentLfu
ConcurrentLfu is a drop in replacement for ConcurrentDictionary, but with bounded size enforced by the W-TinyLFU admission policy. ConcurrentLfu has near optimal hit rate and high scalability. Reads and writes are buffered then replayed asynchronously to mitigate lock contention.
Choose a capacity and use just like ConcurrentDictionary, but with bounded size:
int capacity = 128;
var lfu = new ConcurrentLfu<string, SomeItem>(capacity);
var value = lfu.GetOrAdd("key", (key) => new SomeItem(key));
Documentation
Please refer to the wiki for full API documentation, and a complete analysis of hit rate, latency and throughput.
No packages depend on BitFaster.Caching.
.NET Core 3.1
- No dependencies.
.NET 6.0
- No dependencies.
.NET Standard 2.0
- System.Threading.Tasks.Extensions (>= 4.5.4)
| Version | Downloads | Last updated |
|---|---|---|
| 2.5.4 | 0 | 06/28/2025 |
| 2.5.3 | 0 | 01/13/2025 |
| 2.5.2 | 0 | 09/15/2024 |
| 2.5.1 | 0 | 06/09/2024 |
| 2.5.0 | 0 | 05/09/2024 |
| 2.4.1 | 1 | 02/24/2026 |
| 2.4.0 | 0 | 11/24/2023 |
| 2.3.3 | 0 | 11/11/2023 |
| 2.3.2 | 0 | 10/25/2023 |
| 2.3.1 | 0 | 10/22/2023 |
| 2.3.0 | 0 | 10/06/2023 |
| 2.2.1 | 0 | 08/22/2023 |
| 2.2.0 | 0 | 04/29/2023 |
| 2.1.3 | 0 | 03/17/2023 |
| 2.1.2 | 0 | 03/11/2023 |
| 2.1.1 | 0 | 10/14/2022 |
| 2.1.0 | 0 | 09/11/2022 |
| 2.0.0 | 0 | 07/29/2022 |
| 1.1.0 | 0 | 07/01/2022 |
| 1.0.7 | 0 | 02/13/2022 |
| 1.0.6 | 0 | 11/17/2021 |
| 1.0.5 | 0 | 11/10/2021 |
| 1.0.4 | 0 | 09/11/2021 |
| 1.0.3 | 0 | 05/31/2021 |
| 1.0.2 | 0 | 01/12/2021 |
| 1.0.1 | 0 | 07/09/2020 |
| 1.0.0 | 0 | 07/02/2020 |
| 0.9.4 | 0 | 06/19/2020 |
| 0.9.3 | 0 | 06/16/2020 |
| 0.9.2 | 0 | 06/15/2020 |
| 0.9.1 | 0 | 06/14/2020 |