Ignore 409s in write-through cache

This commit is contained in:
Andrew Kingston 2022-07-25 12:17:40 +01:00
parent 7a41363098
commit f82b407f30
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import BaseCache from "./base"
import { getWritethroughClient } from "../redis/init"
import { logInfo } from "../logging"
const DEFAULT_WRITE_RATE_MS = 10000
let CACHE: BaseCache | null = null
@ -51,10 +52,8 @@ export async function put(
if (err.status !== 409) {
throw err
} else {
// get the rev, update over it - this is risky, may change in future
const readDoc = await db.get(doc._id)
doc._rev = readDoc._rev
await writeDb(doc)
// Swallow 409s but log them
logInfo(`Ignoring conflict in write-through cache`)
}
}
}

View File

@ -15,6 +15,11 @@ export function logAlert(message: string, e?: any) {
console.error(`bb-alert: ${message} ${errorJson}`)
}
export function logInfo(message: string) {
console.warn(`bb-info: ${message}`)
}
export default {
logAlert,
logInfo,
}