adds episode decomposing based on date

This commit is contained in:
TheBeastLT
2020-02-17 09:49:24 +01:00
parent 42ac44d1d9
commit 0125fc6fe5
5 changed files with 74 additions and 22 deletions

View File

@@ -7,10 +7,12 @@ const METADATA_PREFIX = `${GLOBAL_KEY_PREFIX}|metadata`;
const TORRENT_FILES_KEY_PREFIX = `stremio-tpb|files`;
const GLOBAL_TTL = process.env.METADATA_TTL || 7 * 24 * 60 * 60; // 7 days
const MEMORY_TTL = process.env.METADATA_TTL || 2 * 60 * 60; // 2 hours
const MONGO_URI = process.env.MONGODB_URI;
const cache = initiateCache();
const memoryCache = initiateMemoryCache();
const remoteCache = initiateRemoteCache();
const torrentFilesCache = initiateTorrentFilesCache();
function initiateTorrentFilesCache() {
@@ -27,7 +29,7 @@ function initiateTorrentFilesCache() {
}
}
function initiateCache() {
function initiateRemoteCache() {
if (MONGO_URI) {
return cacheManager.caching({
store: mangodbStore,
@@ -46,6 +48,13 @@ function initiateCache() {
}
}
function initiateMemoryCache() {
return cacheManager.caching({
store: 'memory',
ttl: MEMORY_TTL
});
}
function retrieveTorrentFiles(infoHash) {
return torrentFilesCache.get(`${TORRENT_FILES_KEY_PREFIX}:${infoHash}`)
.then((results) => {
@@ -56,16 +65,16 @@ function retrieveTorrentFiles(infoHash) {
});
}
function cacheWrap(key, method, options) {
function cacheWrap(cache, key, method, options) {
return cache.wrap(key, method, options);
}
function cacheWrapImdbId(key, method) {
return cacheWrap(`${IMDB_ID_PREFIX}:${key}`, method, { ttl: GLOBAL_TTL });
return cacheWrap(remoteCache, `${IMDB_ID_PREFIX}:${key}`, method, { ttl: GLOBAL_TTL });
}
function cacheWrapMetadata(id, method) {
return cacheWrap(`${METADATA_PREFIX}:${id}`, method, { ttl: GLOBAL_TTL });
return cacheWrap(memoryCache, `${METADATA_PREFIX}:${id}`, method, { ttl: GLOBAL_TTL });
}
module.exports = { cacheWrapImdbId, cacheWrapMetadata, retrieveTorrentFiles };