centralize options
parent
c23206a23f
commit
efb2a297f9
|
|
@ -1,14 +1,12 @@
|
||||||
import NodeCache from 'node-cache';
|
import NodeCache from 'node-cache';
|
||||||
import getPreviousLotIdFromDatabase from './lotOccupancyDB/getPreviousLotId.js';
|
import getPreviousLotIdFromDatabase from './lotOccupancyDB/getPreviousLotId.js';
|
||||||
import getNextLotIdFromDatabase from './lotOccupancyDB/getNextLotId.js';
|
import getNextLotIdFromDatabase from './lotOccupancyDB/getNextLotId.js';
|
||||||
const timeToLiveMinutes = 2;
|
const cacheOptions = {
|
||||||
const previousLotIdCache = new NodeCache({
|
stdTTL: 2 * 60,
|
||||||
stdTTL: timeToLiveMinutes * 60,
|
|
||||||
useClones: false
|
useClones: false
|
||||||
});
|
};
|
||||||
const nextLotIdCache = new NodeCache({
|
const previousLotIdCache = new NodeCache(cacheOptions);
|
||||||
stdTTL: timeToLiveMinutes * 60
|
const nextLotIdCache = new NodeCache(cacheOptions);
|
||||||
});
|
|
||||||
function cacheLotIds(lotId, nextLotId) {
|
function cacheLotIds(lotId, nextLotId) {
|
||||||
previousLotIdCache.set(nextLotId, lotId);
|
previousLotIdCache.set(nextLotId, lotId);
|
||||||
nextLotIdCache.set(lotId, nextLotId);
|
nextLotIdCache.set(lotId, nextLotId);
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,14 @@ import NodeCache from 'node-cache'
|
||||||
import getPreviousLotIdFromDatabase from './lotOccupancyDB/getPreviousLotId.js'
|
import getPreviousLotIdFromDatabase from './lotOccupancyDB/getPreviousLotId.js'
|
||||||
import getNextLotIdFromDatabase from './lotOccupancyDB/getNextLotId.js'
|
import getNextLotIdFromDatabase from './lotOccupancyDB/getNextLotId.js'
|
||||||
|
|
||||||
const timeToLiveMinutes = 2
|
const cacheOptions: NodeCache.Options = {
|
||||||
|
stdTTL: 2 * 60, // two minutes
|
||||||
const previousLotIdCache = new NodeCache({
|
|
||||||
stdTTL: timeToLiveMinutes * 60,
|
|
||||||
useClones: false
|
useClones: false
|
||||||
})
|
}
|
||||||
|
|
||||||
const nextLotIdCache = new NodeCache({
|
const previousLotIdCache = new NodeCache(cacheOptions)
|
||||||
stdTTL: timeToLiveMinutes * 60
|
|
||||||
})
|
const nextLotIdCache = new NodeCache(cacheOptions)
|
||||||
|
|
||||||
function cacheLotIds(lotId: number, nextLotId: number): void {
|
function cacheLotIds(lotId: number, nextLotId: number): void {
|
||||||
previousLotIdCache.set(nextLotId, lotId)
|
previousLotIdCache.set(nextLotId, lotId)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue