diff --git a/seasoned_api/src/plex/plex.js b/seasoned_api/src/plex/plex.js index 4b5ef09..3659de3 100644 --- a/seasoned_api/src/plex/plex.js +++ b/seasoned_api/src/plex/plex.js @@ -48,13 +48,13 @@ class Plex { this.cache = cache || redisCache; this.cacheTags = { - machineInfo: 'mi', - search: 's' + machineInfo: 'plex/mi', + search: 'plex/s' } } fetchMachineIdentifier() { - const cacheKey = `plex/${this.cacheTags.machineInfo}` + const cacheKey = `${this.cacheTags.machineInfo}` const url = `http://${this.plexIP}:${this.plexPort}/` const options = { timeout: 20000, @@ -130,8 +130,9 @@ class Plex { } search(query) { - const cacheKey = `plex/${this.cacheTags.search}:${query}` - const url = `http://${this.plexIP}:${this.plexPort}/hubs/search?query=${query}` + const cacheKey = `${this.cacheTags.search}:${query}` + + const url = `http://${this.plexIP}:${this.plexPort}/hubs/search?query=${encodeURIComponent(query)}` const options = { timeout: 20000, headers: { 'Accept': 'application/json' } @@ -141,8 +142,8 @@ class Plex { .then(resolve) // if found in cache resolve .catch(() => fetch(url, options)) // else fetch fresh data .then(successfullResponse) + .then(results => this.cache.set(cacheKey, results, 21600)) .then(this.mapResults) - .then(results => this.cache.set(cacheKey, results, 600)) .then(resolve) .catch(error => { if (error != undefined && error.type === 'request-timeout') { diff --git a/seasoned_api/src/tmdb/tmdb.js b/seasoned_api/src/tmdb/tmdb.js index 1e6a8cc..4f03dcc 100644 --- a/seasoned_api/src/tmdb/tmdb.js +++ b/seasoned_api/src/tmdb/tmdb.js @@ -205,7 +205,7 @@ class TMDB { const cacheKey = `tmdb/${this.cacheTags[listname]}:${page}`; return this.getFromCacheOrFetchFromTmdb(cacheKey, listname, query) - .then(response => this.cache.set(cacheKey, response, 10800)) + .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) .then(response => this.mapResults(response, 'movie')) } @@ -214,7 +214,7 @@ class TMDB { const cacheKey = `tmdb/${this.cacheTags[listname]}:${page}`; return this.getFromCacheOrFetchFromTmdb(cacheKey, listName, query) - .then(response => this.cache.set(cacheKey, response, 10800)) + .then(response => this.cache.set(cacheKey, response, this.defaultTTL)) .then(response => this.mapResults(response, 'show')) }