diff --git a/src/core/isAllowed.js b/src/core/isAllowed.js index 20bd9c8..fee68ea 100644 --- a/src/core/isAllowed.js +++ b/src/core/isAllowed.js @@ -70,6 +70,7 @@ async function withoutCache(f, ip) { throw new Error('Proxycheck request did not return yet'); } } + cacheAllowed(ipKey, status); whoisRet = await whois(ip); } finally { await saveIPInfo(ipKey, whoisRet || {}, status, pcheck); @@ -108,11 +109,8 @@ async function withCache(f, ip) { if (checking.indexOf(ipKey) === -1) { checking.push(ipKey); withoutCache(f, ip) - .then((result) => { - cacheAllowed(ipKey, result); - }) .catch((error) => { - logger.error('Error %s', error.message || error); + logger.error('Error %s', error.message); }) .finally(() => { const pos = checking.indexOf(ipKey); diff --git a/src/data/redis/isAllowedCache.js b/src/data/redis/isAllowedCache.js index 3ca5f0d..ebb971a 100644 --- a/src/data/redis/isAllowedCache.js +++ b/src/data/redis/isAllowedCache.js @@ -8,9 +8,9 @@ import client from './client'; const PREFIX = 'isal:'; const CACHE_DURATION = 14 * 24 * 3600; -export function cacheAllowed(ip, allowed) { +export function cacheAllowed(ip, status) { const key = `${PREFIX}:${ip}`; - return client.set(key, allowed.status, { + return client.set(key, status, { EX: CACHE_DURATION, }); }