UNPKG

@security-alliance/octokit-plugin-cache

Version:

Octokit plugin for caching GitHub API responses

30 lines (29 loc) 753 B
import { Octokit } from "@octokit/core"; import { LRUCache } from "lru-cache"; import { wrapRequest } from "./wrap-request.js"; const cache = (octokit, octokitOptions) => { const { enabled = true, options = { max: 1024, ttl: 1e3 * 60 * 60 * 6, maxEntrySize: 1024 * 16, sizeCalculation: (value) => { const contentLengthHeader = value.headers["content-length"]; if (contentLengthHeader === void 0) return 1; return parseInt(contentLengthHeader.toString()); } } } = octokitOptions.cache || {}; if (!enabled) { return {}; } const state = { cache: new LRUCache(options) }; octokit.hook.wrap("request", wrapRequest.bind(null, state)); return {}; }; export { cache };