mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
cache resolved url for longer
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const cacheManager = require('cache-manager');
|
const cacheManager = require('cache-manager');
|
||||||
const mangodbStore = require('cache-manager-mongodb');
|
const mangodbStore = require('cache-manager-mongodb');
|
||||||
|
const { RESOLVER_HOST } = require('../moch/static')
|
||||||
|
|
||||||
const GLOBAL_KEY_PREFIX = 'torrentio-addon';
|
const GLOBAL_KEY_PREFIX = 'torrentio-addon';
|
||||||
const STREAM_KEY_PREFIX = `${GLOBAL_KEY_PREFIX}|stream`;
|
const STREAM_KEY_PREFIX = `${GLOBAL_KEY_PREFIX}|stream`;
|
||||||
@@ -10,7 +11,7 @@ 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 STREAM_EMPTY_TTL = process.env.STREAM_EMPTY_TTL || 30 * 60; // 30 minutes
|
||||||
const AVAILABILITY_TTL = 8 * 60 * 60; // 8 hours
|
const AVAILABILITY_TTL = 8 * 60 * 60; // 8 hours
|
||||||
const AVAILABILITY_EMPTY_TTL = 60 * 60; // 1 hours
|
const AVAILABILITY_EMPTY_TTL = 60 * 60; // 1 hours
|
||||||
const RESOLVED_URL_TTL = 60; // 1 minutes
|
const MESSAGE_VIDEO_URL_TTL = 60; // 1 minutes
|
||||||
// When the streams are empty we want to cache it for less time in case of timeouts or failures
|
// When the streams are empty we want to cache it for less time in case of timeouts or failures
|
||||||
|
|
||||||
const MONGO_URI = process.env.MONGODB_URI;
|
const MONGO_URI = process.env.MONGODB_URI;
|
||||||
@@ -46,7 +47,7 @@ function initiateRemoteCache() {
|
|||||||
function initiateMemoryCache() {
|
function initiateMemoryCache() {
|
||||||
return cacheManager.caching({
|
return cacheManager.caching({
|
||||||
store: 'memory',
|
store: 'memory',
|
||||||
ttl: RESOLVED_URL_TTL,
|
ttl: MESSAGE_VIDEO_URL_TTL,
|
||||||
max: Infinity // infinite LRU cache size
|
max: Infinity // infinite LRU cache size
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,9 @@ function cacheWrapStream(id, method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cacheWrapResolvedUrl(id, method) {
|
function cacheWrapResolvedUrl(id, method) {
|
||||||
return cacheWrap(memoryCache, `${RESOLVED_URL_KEY_PREFIX}:${id}`, method, { ttl: RESOLVED_URL_TTL });
|
return cacheWrap(memoryCache, `${RESOLVED_URL_KEY_PREFIX}:${id}`, method, {
|
||||||
|
ttl: (url) => url.startsWith(RESOLVER_HOST) ? MESSAGE_VIDEO_URL_TTL : STREAM_TTL
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function cacheAvailabilityResults(results) {
|
function cacheAvailabilityResults(results) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const RESOLVER_HOST = process.env.RESOLVER_HOST || 'http://localhost:7050';
|
const RESOLVER_HOST = process.env.RESOLVER_HOST || 'http://localhost:7050';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
RESOLVER_HOST: RESOLVER_HOST,
|
||||||
DOWNLOADING: `${RESOLVER_HOST}/videos/downloading_v2.mp4`,
|
DOWNLOADING: `${RESOLVER_HOST}/videos/downloading_v2.mp4`,
|
||||||
FAILED_DOWNLOAD: `${RESOLVER_HOST}/videos/download_failed_v2.mp4`,
|
FAILED_DOWNLOAD: `${RESOLVER_HOST}/videos/download_failed_v2.mp4`,
|
||||||
FAILED_ACCESS: `${RESOLVER_HOST}/videos/failed_access_v2.mp4`,
|
FAILED_ACCESS: `${RESOLVER_HOST}/videos/failed_access_v2.mp4`,
|
||||||
|
|||||||
Reference in New Issue
Block a user