From b36a9c098387abd07a33f5f832e3013b27197724 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Tue, 12 May 2020 13:25:49 +0200 Subject: [PATCH] [addon] remove memory cache as dynamic ttl is not supported --- addon/lib/cache.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/addon/lib/cache.js b/addon/lib/cache.js index 40c10a8..da067b6 100644 --- a/addon/lib/cache.js +++ b/addon/lib/cache.js @@ -9,7 +9,7 @@ const USER_AGENT_KEY_PREFIX = `${GLOBAL_KEY_PREFIX}|agent`; const STREAM_TTL = process.env.STREAM_TTL || 4 * 60 * 60; // 4 hours const STREAM_EMPTY_TTL = process.env.STREAM_EMPTY_TTL || 30 * 60; // 30 minutes -const RESOLVED_URL_TTL = 60; // 1 minutes +const RESOLVED_URL_TTL = 2 * 60; // 2 minutes const PROXY_TTL = 60 * 60; // 60 minutes const USER_AGENT_TTL = 2 * 24 * 60 * 60; // 2 days // When the streams are empty we want to cache it for less time in case of timeouts or failures @@ -17,7 +17,6 @@ const USER_AGENT_TTL = 2 * 24 * 60 * 60; // 2 days const MONGO_URI = process.env.MONGODB_URI; const NO_CACHE = process.env.NO_CACHE || false; -const memoryCache = initiateMemoryCache(); const remoteCache = initiateRemoteCache(); function initiateRemoteCache() { @@ -31,26 +30,19 @@ function initiateRemoteCache() { collection: 'torrentio_addon_collection', useNewUrlParser: true, useUnifiedTopology: false, - ttl: STREAM_TTL + ttl: STREAM_EMPTY_TTL }, - ttl: STREAM_TTL, + ttl: STREAM_EMPTY_TTL, ignoreCacheErrors: true }); } else { return cacheManager.caching({ store: 'memory', - ttl: STREAM_TTL + ttl: STREAM_EMPTY_TTL }); } } -function initiateMemoryCache() { - return cacheManager.caching({ - store: 'memory', - ttl: STREAM_TTL - }); -} - function cacheWrap(cache, key, method, options) { if (NO_CACHE || !cache) { return method(); @@ -65,15 +57,15 @@ function cacheWrapStream(id, method) { } function cacheWrapResolvedUrl(id, method) { - return cacheWrap(memoryCache, `${RESOLVED_URL_KEY_PREFIX}:${id}`, method, { ttl: { RESOLVED_URL_TTL } }); + return cacheWrap(remoteCache, `${RESOLVED_URL_KEY_PREFIX}:${id}`, method, { ttl: RESOLVED_URL_TTL }); } function cacheWrapProxy(id, method) { - return cacheWrap(memoryCache, `${PROXY_KEY_PREFIX}:${id}`, method, { ttl: { PROXY_TTL } }); + return cacheWrap(remoteCache, `${PROXY_KEY_PREFIX}:${id}`, method, { ttl: PROXY_TTL }); } function cacheUserAgent(id, method) { - return cacheWrap(memoryCache, `${USER_AGENT_KEY_PREFIX}:${id}`, method, { ttl: { USER_AGENT_TTL } }); + return cacheWrap(remoteCache, `${USER_AGENT_KEY_PREFIX}:${id}`, method, { ttl: USER_AGENT_TTL }); } module.exports = { cacheWrapStream, cacheWrapResolvedUrl, cacheWrapProxy, cacheUserAgent };