Skip to content

Commit b7a0264

Browse files
geroplroboquat
authored andcommitted
[server] GitHub API: ensure that we don't
1 parent 2631195 commit b7a0264

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

components/gitpod-protocol/src/util/garbage-collected-cache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class GarbageCollectedCache<T> {
4141
return entry.value;
4242
}
4343

44+
public delete(key: string) {
45+
this.store.delete(key);
46+
}
47+
4448
protected regularlyCollectGarbage() {
4549
setInterval(() => this.collectGarbage(), this.gcIntervalSeconds * 1000);
4650
}

components/server/src/github/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { OctokitResponse } from "@octokit/types"
1010
import { OctokitOptions } from "@octokit/core/dist-types/types"
1111

1212
import { Branch, CommitInfo, User } from "@gitpod/gitpod-protocol"
13+
import { GarbageCollectedCache } from "@gitpod/gitpod-protocol/lib/util/garbage-collected-cache";
1314
import { injectable, inject } from 'inversify';
1415
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
1516
import { GitHubScope } from './scopes';
@@ -185,7 +186,7 @@ export class GitHubRestApi {
185186
}
186187
}
187188

188-
protected readonly cachedResponses = new Map<string, OctokitResponse<any>>();
189+
protected readonly cachedResponses = new GarbageCollectedCache<OctokitResponse<any>>(120, 150);
189190
public async runWithCache(key: string, user: User, operation: (api: Octokit) => Promise<OctokitResponse<any>>): Promise<OctokitResponse<any>> {
190191
const result = new Deferred<OctokitResponse<any>>();
191192
const before = new Date().getTime();

0 commit comments

Comments
 (0)