Add disk caching for youtube api calls

Fixes https://github.com/ajayyy/SponsorBlockServer/issues/239
This commit is contained in:
Ajay Ramachandran
2021-06-26 23:21:51 -04:00
parent e1cf360825
commit 07ab48da1f
8 changed files with 307 additions and 53 deletions

32
src/utils/diskCache.ts Normal file
View File

@@ -0,0 +1,32 @@
import LRU from "@ajayyy/lru-diskcache";
import { config } from "../config";
let DiskCache: LRU<string, string>;
if (config.diskCache) {
DiskCache = new LRU('./databases/cache', config.diskCache);
DiskCache.init();
} else {
DiskCache = {
// constructor(rootPath, options): {};
init() {},
reset() {},
has(key) { return false; },
get(key, opts) { return null; },
// Returns size
set(key, dataOrSteam) { return new Promise((resolve) => 0); },
del(key) {},
size() { return 0; },
prune() {},
};
}
export default DiskCache;