mirror of
https://github.com/TheBeastLT/torrentio-scraper.git
synced 2026-01-11 22:40:22 +00:00
update cache manager usage
This commit is contained in:
parent
0a45dde099
commit
0cd43f1f56
4 changed files with 802 additions and 715 deletions
|
|
@ -41,7 +41,7 @@ builder.defineCatalogHandler((args) => {
|
|||
staleRevalidate: STALE_REVALIDATE_AGE,
|
||||
staleError: STALE_ERROR_AGE
|
||||
}))
|
||||
.catch(error => Promise.reject(`Failed retrieving catalog ${args.id}: ${error.message}`));
|
||||
.catch(error => Promise.reject(`Failed retrieving catalog ${args.id}: ${error.message || error}`));
|
||||
})
|
||||
|
||||
async function getCursor(catalog, providers, genre, offset) {
|
||||
|
|
|
|||
|
|
@ -1,46 +1,28 @@
|
|||
import cacheManager from 'cache-manager';
|
||||
import mangodbStore from 'cache-manager-mongodb';
|
||||
import KeyvMongo from "@keyv/mongo";
|
||||
|
||||
const CATALOG_TTL = process.env.STREAM_TTL || 24 * 60 * 60; // 24 hours
|
||||
const CATALOG_TTL = 24 * 60 * 60 * 1000; // 24 hours
|
||||
|
||||
const MONGO_URI = process.env.MONGODB_URI;
|
||||
|
||||
const remoteCache = initiateRemoteCache();
|
||||
const remoteCache = MONGO_URI && new KeyvMongo(MONGO_URI, { collection: 'torrentio_catalog_collection' });
|
||||
|
||||
function initiateRemoteCache() {
|
||||
if (MONGO_URI) {
|
||||
return cacheManager.caching({
|
||||
store: mangodbStore,
|
||||
uri: MONGO_URI,
|
||||
options: {
|
||||
collection: 'torrentio_catalog_collection',
|
||||
socketTimeoutMS: 120000,
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: false,
|
||||
ttl: CATALOG_TTL
|
||||
},
|
||||
ttl: CATALOG_TTL,
|
||||
ignoreCacheErrors: true
|
||||
});
|
||||
} else {
|
||||
return cacheManager.caching({
|
||||
store: 'memory',
|
||||
ttl: CATALOG_TTL
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function cacheWrap(cache, key, method, options) {
|
||||
async function cacheWrap(cache, key, method, ttl) {
|
||||
if (!cache) {
|
||||
return method();
|
||||
}
|
||||
return cache.wrap(key, method, options);
|
||||
const value = await remoteCache.get(key);
|
||||
if (value !== undefined) {
|
||||
return value;
|
||||
}
|
||||
const result = await method();
|
||||
await remoteCache.set(key, result, ttl);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function cacheWrapCatalog(key, method) {
|
||||
return cacheWrap(remoteCache, key, method, { ttl: CATALOG_TTL });
|
||||
return cacheWrap(remoteCache, key, method, CATALOG_TTL);
|
||||
}
|
||||
|
||||
export function cacheWrapIds(key, method) {
|
||||
return cacheWrap(remoteCache, `ids|${key}`, method, { ttl: CATALOG_TTL });
|
||||
return cacheWrap(remoteCache, `ids|${key}`, method, CATALOG_TTL);
|
||||
}
|
||||
|
|
|
|||
1458
catalogs/package-lock.json
generated
1458
catalogs/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -7,20 +7,19 @@
|
|||
"start": "node index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "16.x"
|
||||
"node": ">=16.x"
|
||||
},
|
||||
"author": "TheBeastLT <pauliox@beyond.lt>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^1.6.1",
|
||||
"@keyv/mongo": "^3.0.1",
|
||||
"axios": "^1.7.7",
|
||||
"bottleneck": "^2.19.5",
|
||||
"cache-manager": "^3.4.4",
|
||||
"cache-manager-mongodb": "^0.3.0",
|
||||
"moment": "^2.29.4",
|
||||
"pg": "^8.8.0",
|
||||
"moment": "^2.30.1",
|
||||
"pg": "^8.13.1",
|
||||
"pg-hstore": "^2.3.4",
|
||||
"request-ip": "^3.3.0",
|
||||
"sequelize": "^6.29.0",
|
||||
"sequelize": "^6.37.5",
|
||||
"stremio-addon-sdk": "^1.6.10"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue