Misc updates to caching from plex and tmdb.
This commit is contained in:
@@ -48,13 +48,13 @@ class Plex {
|
|||||||
|
|
||||||
this.cache = cache || redisCache;
|
this.cache = cache || redisCache;
|
||||||
this.cacheTags = {
|
this.cacheTags = {
|
||||||
machineInfo: 'mi',
|
machineInfo: 'plex/mi',
|
||||||
search: 's'
|
search: 'plex/s'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchMachineIdentifier() {
|
fetchMachineIdentifier() {
|
||||||
const cacheKey = `plex/${this.cacheTags.machineInfo}`
|
const cacheKey = `${this.cacheTags.machineInfo}`
|
||||||
const url = `http://${this.plexIP}:${this.plexPort}/`
|
const url = `http://${this.plexIP}:${this.plexPort}/`
|
||||||
const options = {
|
const options = {
|
||||||
timeout: 20000,
|
timeout: 20000,
|
||||||
@@ -130,8 +130,9 @@ class Plex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search(query) {
|
search(query) {
|
||||||
const cacheKey = `plex/${this.cacheTags.search}:${query}`
|
const cacheKey = `${this.cacheTags.search}:${query}`
|
||||||
const url = `http://${this.plexIP}:${this.plexPort}/hubs/search?query=${query}`
|
|
||||||
|
const url = `http://${this.plexIP}:${this.plexPort}/hubs/search?query=${encodeURIComponent(query)}`
|
||||||
const options = {
|
const options = {
|
||||||
timeout: 20000,
|
timeout: 20000,
|
||||||
headers: { 'Accept': 'application/json' }
|
headers: { 'Accept': 'application/json' }
|
||||||
@@ -141,8 +142,8 @@ class Plex {
|
|||||||
.then(resolve) // if found in cache resolve
|
.then(resolve) // if found in cache resolve
|
||||||
.catch(() => fetch(url, options)) // else fetch fresh data
|
.catch(() => fetch(url, options)) // else fetch fresh data
|
||||||
.then(successfullResponse)
|
.then(successfullResponse)
|
||||||
|
.then(results => this.cache.set(cacheKey, results, 21600))
|
||||||
.then(this.mapResults)
|
.then(this.mapResults)
|
||||||
.then(results => this.cache.set(cacheKey, results, 600))
|
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error != undefined && error.type === 'request-timeout') {
|
if (error != undefined && error.type === 'request-timeout') {
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ class TMDB {
|
|||||||
const cacheKey = `tmdb/${this.cacheTags[listname]}:${page}`;
|
const cacheKey = `tmdb/${this.cacheTags[listname]}:${page}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, listname, query)
|
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'))
|
.then(response => this.mapResults(response, 'movie'))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ class TMDB {
|
|||||||
const cacheKey = `tmdb/${this.cacheTags[listname]}:${page}`;
|
const cacheKey = `tmdb/${this.cacheTags[listname]}:${page}`;
|
||||||
|
|
||||||
return this.getFromCacheOrFetchFromTmdb(cacheKey, listName, query)
|
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'))
|
.then(response => this.mapResults(response, 'show'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user