Removing old caching code.
This commit is contained in:
parent
76f19def26
commit
ee345af60d
|
@ -1,6 +1,5 @@
|
||||||
const { Client, utils } = require("@budibase/backend-core/redis")
|
const { Client, utils } = require("@budibase/backend-core/redis")
|
||||||
const { newid } = require("@budibase/backend-core/utils")
|
const { newid } = require("@budibase/backend-core/utils")
|
||||||
const env = require("../environment")
|
|
||||||
|
|
||||||
function getExpirySecondsForDB(db) {
|
function getExpirySecondsForDB(db) {
|
||||||
switch (db) {
|
switch (db) {
|
||||||
|
@ -13,7 +12,7 @@ function getExpirySecondsForDB(db) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let pwResetClient, invitationClient, cachingClient
|
let pwResetClient, invitationClient
|
||||||
|
|
||||||
function getClient(db) {
|
function getClient(db) {
|
||||||
switch (db) {
|
switch (db) {
|
||||||
|
@ -21,8 +20,6 @@ function getClient(db) {
|
||||||
return pwResetClient
|
return pwResetClient
|
||||||
case utils.Databases.INVITATIONS:
|
case utils.Databases.INVITATIONS:
|
||||||
return invitationClient
|
return invitationClient
|
||||||
case utils.Databases.GENERIC_CACHE:
|
|
||||||
return cachingClient
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,10 +45,8 @@ async function getACode(db, code, deleteCode = true) {
|
||||||
exports.init = async () => {
|
exports.init = async () => {
|
||||||
pwResetClient = new Client(utils.Databases.PW_RESETS)
|
pwResetClient = new Client(utils.Databases.PW_RESETS)
|
||||||
invitationClient = new Client(utils.Databases.INVITATIONS)
|
invitationClient = new Client(utils.Databases.INVITATIONS)
|
||||||
cachingClient = new Client(utils.Databases.DATA_CACHE)
|
|
||||||
await pwResetClient.init()
|
await pwResetClient.init()
|
||||||
await invitationClient.init()
|
await invitationClient.init()
|
||||||
await cachingClient.init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,23 +105,3 @@ exports.checkInviteCode = async (inviteCode, deleteCode = true) => {
|
||||||
throw "Invitation is not valid or has expired, please request a new one."
|
throw "Invitation is not valid or has expired, please request a new one."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move into backend-core
|
|
||||||
exports.withCache = async (key, ttl, fetchFn) => {
|
|
||||||
const cachedValue = await cachingClient.get(key)
|
|
||||||
if (cachedValue) {
|
|
||||||
return cachedValue
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const fetchedValue = await fetchFn()
|
|
||||||
|
|
||||||
if (!env.isTest()) {
|
|
||||||
await cachingClient.store(key, fetchedValue, ttl)
|
|
||||||
}
|
|
||||||
return fetchedValue
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error calling fetch function", err)
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue