Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace lru-cache with toad-cache #654

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@octokit/request": "^9.1.1",
"@octokit/request-error": "^6.1.1",
"@octokit/types": "^13.4.1",
"lru-cache": "npm:@wolfy1339/lru-cache@^11.0.2-patch.1",
"toad-cache": "^3.7.0",
"universal-github-app-jwt": "^2.2.0",
"universal-user-agent": "^7.0.0"
},
Expand Down
11 changes: 5 additions & 6 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// https://github.com/isaacs/node-lru-cache#readme
import { LRUCache } from "lru-cache";
import { Lru } from "toad-cache";

/* v8 ignore next */
import type {
Expand All @@ -12,12 +11,12 @@ import type {
} from "./types.js";

export function getCache() {
return new LRUCache<number, string>({
return new Lru<string>(
// cache max. 15000 tokens, that will use less than 10mb memory
max: 15000,
15000,
// Cache for 1 minute less than GitHub expiry
ttl: 1000 * 60 * 59,
});
1000 * 60 * 59,
);
}

export async function get(
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as OctokitTypes from "@octokit/types";
import type { LRUCache } from "lru-cache";
import type { Lru } from "toad-cache";
import type * as OAuthAppAuth from "@octokit/auth-oauth-app";

// STRATEGY OPTIONS
Expand Down Expand Up @@ -134,7 +134,7 @@ export type Route = OctokitTypes.Route;
export type RequestInterface = OctokitTypes.RequestInterface;

export type Cache =
| LRUCache<string, string>
| Lru<string>
| {
get: (key: string) => string | Promise<string>;
set: (key: string, value: string) => any;
Expand Down