mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-03-13 22:12:42 +03:00
Switch to simple lru cache
This commit is contained in:
26
package-lock.json
generated
26
package-lock.json
generated
@@ -9,6 +9,7 @@
|
||||
"version": "0.1.0",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@ajayyy/simple-lru-cache": "^1.1.2",
|
||||
"axios": "^1.13.6",
|
||||
"better-sqlite3": "^11.2.1",
|
||||
"cron": "^2.1.0",
|
||||
@@ -17,7 +18,6 @@
|
||||
"express-rate-limit": "^6.7.0",
|
||||
"form-data": "^4.0.4",
|
||||
"lodash": "^4.17.23",
|
||||
"lru-cache": "^10.2.0",
|
||||
"lz4-napi": "^2.2.0",
|
||||
"pg": "^8.8.0",
|
||||
"rate-limit-redis": "^3.0.1",
|
||||
@@ -51,6 +51,12 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@ajayyy/simple-lru-cache": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@ajayyy/simple-lru-cache/-/simple-lru-cache-1.1.2.tgz",
|
||||
"integrity": "sha512-X1SRyVSK9xTyFQoZPf66IxtraRQbLkFWl93TRBtKft3V7NU8/KGuPWlIddilvxYwkrjSHKU6WYNN0mCgHBYYhg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
|
||||
@@ -3859,14 +3865,6 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz",
|
||||
"integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==",
|
||||
"engines": {
|
||||
"node": "14 || >=16.14"
|
||||
}
|
||||
},
|
||||
"node_modules/luxon": {
|
||||
"version": "1.28.1",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.28.1.tgz",
|
||||
@@ -6137,6 +6135,11 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@ajayyy/simple-lru-cache": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@ajayyy/simple-lru-cache/-/simple-lru-cache-1.1.2.tgz",
|
||||
"integrity": "sha512-X1SRyVSK9xTyFQoZPf66IxtraRQbLkFWl93TRBtKft3V7NU8/KGuPWlIddilvxYwkrjSHKU6WYNN0mCgHBYYhg=="
|
||||
},
|
||||
"@ampproject/remapping": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
|
||||
@@ -8878,11 +8881,6 @@
|
||||
"is-unicode-supported": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz",
|
||||
"integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q=="
|
||||
},
|
||||
"luxon": {
|
||||
"version": "1.28.1",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.28.1.tgz",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"express-rate-limit": "^6.7.0",
|
||||
"form-data": "^4.0.4",
|
||||
"lodash": "^4.17.23",
|
||||
"lru-cache": "^10.2.0",
|
||||
"@ajayyy/simple-lru-cache": "^1.1.2",
|
||||
"lz4-napi": "^2.2.0",
|
||||
"pg": "^8.8.0",
|
||||
"rate-limit-redis": "^3.0.1",
|
||||
|
||||
@@ -7,7 +7,7 @@ import { RedisReply } from "rate-limit-redis";
|
||||
import { db } from "../databases/databases";
|
||||
import { Postgres } from "../databases/Postgres";
|
||||
import { compress, uncompress } from "lz4-napi";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { LRUCache } from "@ajayyy/simple-lru-cache/dist/index";
|
||||
import { shouldClientCacheKey } from "./redisKeys";
|
||||
import { ZMember } from "@redis/client/dist/lib/commands/generic-transformers";
|
||||
|
||||
@@ -79,15 +79,12 @@ const activeRequestPromises: Record<string, Promise<string>> = {};
|
||||
const resetKeys: Set<RedisCommandArgument> = new Set();
|
||||
const cache = config.redis.clientCacheSize ? new LRUCache<RedisCommandArgument, string>({
|
||||
maxSize: config.redis.clientCacheSize,
|
||||
sizeCalculation: (value) => value.length,
|
||||
ttl: 1000 * 60 * 30,
|
||||
ttlResolution: 1000 * 60 * 15
|
||||
ttl: 1000 * 60 * 30
|
||||
}) : null;
|
||||
// Used to cache ttl data
|
||||
const ttlCache = config.redis.clientCacheSize ? new LRUCache<RedisCommandArgument, number>({
|
||||
max: config.redis.clientCacheSize / 10 / 4, // 4 byte integer per element
|
||||
ttl: 1000 * 60 * 30,
|
||||
ttlResolution: 1000 * 60 * 15
|
||||
maxElements: config.redis.clientCacheSize / 10 / 4, // 4 byte integer per element
|
||||
ttl: 1000 * 60 * 30
|
||||
}) : null;
|
||||
|
||||
// For redis
|
||||
@@ -406,8 +403,8 @@ export function getRedisStats(): RedisStats {
|
||||
avgWriteTime: writeResponseTime.length > 0 ? writeResponseTime.reduce((a, b) => a + b, 0) / writeResponseTime.length : 0,
|
||||
memoryCacheHits: memoryCacheHits / (memoryCacheHits + memoryCacheMisses),
|
||||
memoryCacheTotalHits: memoryCacheHits / (memoryCacheHits + memoryCacheMisses + memoryCacheUncachedMisses),
|
||||
memoryCacheLength: cache?.size ?? 0,
|
||||
memoryCacheSize: cache?.calculatedSize ?? 0,
|
||||
memoryCacheLength: cache?.currentElementCount ?? 0,
|
||||
memoryCacheSize: cache?.currentSize ?? 0,
|
||||
lastInvalidation,
|
||||
lastInvalidationMessage
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user