From efb2a297f9c47f577da502b4b18dc85fab07bd8a Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Wed, 25 Jan 2023 13:09:14 -0500 Subject: [PATCH] centralize options --- helpers/functions.lots.js | 12 +++++------- helpers/functions.lots.ts | 14 ++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/helpers/functions.lots.js b/helpers/functions.lots.js index a86bc559..c8820552 100644 --- a/helpers/functions.lots.js +++ b/helpers/functions.lots.js @@ -1,14 +1,12 @@ import NodeCache from 'node-cache'; import getPreviousLotIdFromDatabase from './lotOccupancyDB/getPreviousLotId.js'; import getNextLotIdFromDatabase from './lotOccupancyDB/getNextLotId.js'; -const timeToLiveMinutes = 2; -const previousLotIdCache = new NodeCache({ - stdTTL: timeToLiveMinutes * 60, +const cacheOptions = { + stdTTL: 2 * 60, useClones: false -}); -const nextLotIdCache = new NodeCache({ - stdTTL: timeToLiveMinutes * 60 -}); +}; +const previousLotIdCache = new NodeCache(cacheOptions); +const nextLotIdCache = new NodeCache(cacheOptions); function cacheLotIds(lotId, nextLotId) { previousLotIdCache.set(nextLotId, lotId); nextLotIdCache.set(lotId, nextLotId); diff --git a/helpers/functions.lots.ts b/helpers/functions.lots.ts index 21328d9a..5a0d2fa8 100644 --- a/helpers/functions.lots.ts +++ b/helpers/functions.lots.ts @@ -3,16 +3,14 @@ import NodeCache from 'node-cache' import getPreviousLotIdFromDatabase from './lotOccupancyDB/getPreviousLotId.js' import getNextLotIdFromDatabase from './lotOccupancyDB/getNextLotId.js' -const timeToLiveMinutes = 2 - -const previousLotIdCache = new NodeCache({ - stdTTL: timeToLiveMinutes * 60, +const cacheOptions: NodeCache.Options = { + stdTTL: 2 * 60, // two minutes useClones: false -}) +} -const nextLotIdCache = new NodeCache({ - stdTTL: timeToLiveMinutes * 60 -}) +const previousLotIdCache = new NodeCache(cacheOptions) + +const nextLotIdCache = new NodeCache(cacheOptions) function cacheLotIds(lotId: number, nextLotId: number): void { previousLotIdCache.set(nextLotId, lotId)