Skip to content

Commit 727f183

Browse files
💡 use cache for new GhClient
1 parent cd76210 commit 727f183

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

source/GitHubApp/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Gttsb.Core;
22
using Gttsb.Gh;
3+
using Microsoft.Extensions.Caching.Memory;
34

45
var builder = WebApplication.CreateBuilder(args);
56

67
// Add services to the container.
78
builder.Services.Configure<AppOptions>(builder.Configuration.GetSection("GitHubApp"));
89
builder.Services.Configure<AzureOptions>(builder.Configuration.GetSection("Azure"));
10+
builder.Services.AddSingleton<IMemoryCache>(new MemoryCache(new MemoryCacheOptions()));
911

1012
builder.Services.AddSingleton<IGitHubFacadeFactory, GitHubFacadeFactory>();
1113
builder.Services.AddSingleton<IActiveDirectoryFacadeFactory, ActiveDirectoryFacadeFactory>();

source/Gttsb.Gh/GitHubFacadeFactory.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Gttsb.Core;
2+
using Microsoft.Extensions.Caching.Memory;
23
using Microsoft.Extensions.Options;
34
using Microsoft.IdentityModel.Tokens;
45
using Octokit;
@@ -11,10 +12,12 @@ namespace Gttsb.Gh
1112
public sealed class GitHubFacadeFactory : IGitHubFacadeFactory
1213
{
1314
private readonly IOptions<AppOptions> options;
15+
private IMemoryCache cache;
1416

15-
public GitHubFacadeFactory(IOptions<AppOptions> options)
17+
public GitHubFacadeFactory(IOptions<AppOptions> options, IMemoryCache cache)
1618
{
1719
this.options = options;
20+
this.cache = cache;
1821
}
1922

2023
private IGitHubClient GetInitialClient(AppOptions options)
@@ -48,7 +51,11 @@ public async Task<IInstalledGitHubFacade> CreateClientForOrgAsync(Core.Installat
4851

4952
var connection = new Octokit.GraphQL.Connection(new Octokit.GraphQL.ProductHeaderValue(productHeaderName), response.Token);
5053

51-
return new InstalledGitHubFacade(installationClient, connection, installation.OrgName);
54+
var installedClient = new InstalledGitHubFacade(installationClient, connection, installation.OrgName);
55+
56+
var withCacheDecorator = new GitHubFacadeCacheDecorator(installedClient, cache);
57+
58+
return withCacheDecorator;
5259
}
5360

5461
public async Task<IEnumerable<Core.Installation>> GetInstallationsAsync()

0 commit comments

Comments
 (0)