Skip to content

Cache Builders

Alex Peck edited this page Sep 20, 2022 · 12 revisions

All cache features come with a small amount of overhead. Performance matters. Therefore, features are disabled by default to provide maximum performance. Choose only what is needed to solve the problem at hand, without any unwanted tax.

Builders are provided for both ConcurrentLru and ConcurrentLfu to make it easy to configure more advanced caches with the requisite features.

For example, this is how to create a ConcurrentLru with scoped values, and GetOrAdd that is both async and has atomic value creation:

IScopedAsyncCache<int, Disposable> lru = new ConcurrentLruBuilder<int, Disposable>()
   .WithAtomicGetOrAdd()
   .AsScopedCache()
   .AsAsyncCache()
   .WithCapacity(3)
   .Build();