perf: cache slow-changing data (series, movies, tags) with 60s TTL
All checks were successful
Build and Push Docker Image / build (push) Successful in 27s

- Add MemoryCache utility with get/set/invalidate/clear
- Cache Sonarr series, Sonarr tags, Radarr movies, Radarr tags
- 60-second TTL - first request fetches, subsequent requests served from cache
- Queue, history, and torrent data remain uncached (changes frequently)
- On cache hit, these 4 heavy API calls resolve instantly
This commit is contained in:
2026-05-15 23:32:45 +01:00
parent eda9770f49
commit b04b52e3f1
2 changed files with 94 additions and 34 deletions

36
server/utils/cache.js Normal file
View File

@@ -0,0 +1,36 @@
const { logToFile } = require('./logger');
class MemoryCache {
constructor() {
this.store = new Map();
}
get(key) {
const entry = this.store.get(key);
if (!entry) return null;
if (Date.now() > entry.expiresAt) {
this.store.delete(key);
return null;
}
return entry.value;
}
set(key, value, ttlMs) {
this.store.set(key, {
value,
expiresAt: Date.now() + ttlMs
});
}
invalidate(key) {
this.store.delete(key);
}
clear() {
this.store.clear();
}
}
const cache = new MemoryCache();
module.exports = cache;