diff --git a/addon/addon.js b/addon/addon.js index 670e3f8..aa9662d 100644 --- a/addon/addon.js +++ b/addon/addon.js @@ -27,10 +27,10 @@ builder.defineStreamHandler((args) => { return Promise.resolve({ streams: [] }); } - return limiter.schedule(() => streamHandler(args) + return cacheWrapStream(args.id, () => limiter.schedule(() => streamHandler(args) .then(records => records .sort((a, b) => b.torrent.seeders - a.torrent.seeders || b.torrent.uploadDate - a.torrent.uploadDate) - .map(record => toStreamInfo(record)))) + .map(record => toStreamInfo(record))))) .then(streams => applyFilters(streams, args.extra)) .then(streams => applySorting(streams, args.extra)) .then(streams => applyStaticInfo(streams)) diff --git a/addon/lib/cache.js b/addon/lib/cache.js index 047a8ad..5fcdd90 100644 --- a/addon/lib/cache.js +++ b/addon/lib/cache.js @@ -18,7 +18,7 @@ const MONGO_URI = process.env.MONGODB_URI; const NO_CACHE = process.env.NO_CACHE || false; const memoryCache = initiateMemoryCache(); -// const remoteCache = initiateRemoteCache(); +const remoteCache = initiateRemoteCache(); function initiateRemoteCache() { if (NO_CACHE) { @@ -62,7 +62,7 @@ function cacheWrap(cache, key, method, options) { } function cacheWrapStream(id, method) { - return cacheWrap(memoryCache, `${STREAM_KEY_PREFIX}:${id}`, method, { + return cacheWrap(remoteCache, `${STREAM_KEY_PREFIX}:${id}`, method, { ttl: (streams) => streams.length ? STREAM_TTL : STREAM_EMPTY_TTL }); }