Skip to content

Commit 7b7dca8

Browse files
authored
Merge pull request #1 from bitfaster/users/alexpeck/outline
outline
2 parents 0e40442 + 0d001cb commit 7b7dca8

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32819.101
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitFaster.Caching.DependencyInjection", "BitFaster.Caching.DependencyInjection\BitFaster.Caching.DependencyInjection.csproj", "{337F4327-E35A-40F6-8A6C-7FA47A962D49}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{337F4327-E35A-40F6-8A6C-7FA47A962D49}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {444CBAA7-C7F1-4332-9162-9D98701D3883}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="BitFaster.Caching" Version="2.1.0" />
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using BitFaster.Caching.Lfu;
2+
using BitFaster.Caching.Lru;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.DependencyInjection.Extensions;
5+
using System;
6+
7+
namespace BitFaster.Caching.DependencyInjection
8+
{
9+
/// <summary>
10+
/// Extension methods for setting up caches in an <see cref="IServiceCollection" />.
11+
/// </summary>
12+
public static class CacheExtensions
13+
{
14+
/// <summary>
15+
/// Adds a <see cref="ConcurrentLru{K,V}" />to the <see cref="IServiceCollection" />.
16+
/// </summary>
17+
/// <typeparam name="K">The type of the key.</typeparam>
18+
/// <typeparam name="V">The type of the values.</typeparam>
19+
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
20+
/// <param name="configure">A delegate which can use a cache builder to build a cache.</param>
21+
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
22+
public static IServiceCollection AddConcurrentLru<K, V>(this IServiceCollection services, Action<ConcurrentLruBuilder<K, V>> configure)
23+
{
24+
// this is not so simple because the builder can change the return type.
25+
26+
var builder = new ConcurrentLruBuilder<K, V>();
27+
configure(builder);
28+
services.TryAddSingleton<ICache<K, V>>(builder.Build());
29+
return services;
30+
}
31+
32+
public static IServiceCollection AddConcurrentLfu<K, V>(this IServiceCollection services, Action<ConcurrentLfuBuilder<K, V>> configure)
33+
{
34+
var builder = new ConcurrentLfuBuilder<K, V>();
35+
configure(builder);
36+
services.TryAddSingleton<ICache<K, V>>(builder.Build());
37+
return services;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)