-
Notifications
You must be signed in to change notification settings - Fork 457
When using the SQLitecache
, must I ensure the machine is a primary?
#1038
-
I've followed the caching docs and when I run it in production, I get Disk I/O SQLite errors:
2025年09月04日T19:33:55Z app[784049ef491948] iad [info]level=INFO msg="fuse: write(): wal error: read only replica" error setting cache: challenge:mallorca-championships-presented-by-ecotrans-group-2025-served-2025 Error: disk I/O error 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at Object.set (file:///myapp/app/utils/cache.server.ts:154:16) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at getFreshValue (file:///myapp/node_modules/@epic-web/cachified/src/getFreshValue.ts:65:19) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at cachified (file:///myapp/node_modules/@epic-web/cachified/src/cachified.ts:94:17) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at getChallenge (file:///myapp/app/utils/challenge.server.ts:32:18) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at getTournamentContextMain (file:///myapp/app/utils/tournament-context.server.ts:60:18) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at loader9ドル (file:///myapp/app/routes/tournaments+/$slug+/$tour+/index.tsx:38:9) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at callRouteHandler (file:///myapp/node_modules/react-router/dist/development/chunk-5UALIXAM.mjs:509:16) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at commonRoute.loader (file:///myapp/node_modules/react-router/dist/development/chunk-5UALIXAM.mjs:658:19) 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at file:///myapp/node_modules/react-router/dist/development/chunk-PVWAREVJ.mjs:4259:19 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] at callLoaderOrAction (file:///myapp/node_modules/react-router/dist/development/chunk-PVWAREVJ.mjs:4311:16) { 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] code: 'ERR_SQLITE_ERROR', 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] errcode: 778, 2025年09月04日T19:33:55Z app[784049ef491948] iad [info] errstr: 'disk I/O error' 2025年09月04日T19:33:55Z app[784049ef491948] iad [info]}
To use the SQLite cache, do we have to first use ensurePrimary()
before saving to it? If so, can the docs be updated to reflect that?
Beta Was this translation helpful? Give feedback.
All reactions
Whoops! I made a mistake by removing the utility that made the cache multi-region safe. I've just pushed this commit to fix it: a1b3aa4
My apologies! Thank you for bringing it up.
As a note, you wouldn't want to use ensurePrimary
for this because so many requests result in a cache update that you'd pretty much never benefit from having multiple regions. So instead we trigger a request to the primary when the cache needs to be updated.
Replies: 1 comment 3 replies
-
How are you using it? Are you trying to write to it directly? It's intended to be used with cachified (in the cache.server.ts file). That handles updating the cache for you in an efficient way.
Beta Was this translation helpful? Give feedback.
All reactions
-
I basically copied the implementation from the docs, using cachified:
const topPredictions = await cachified({ key: `tournament:topPredictions:v1:${tournament.slug}:${challenge ? challenge.id : 'no-challenge'}`, cache: cache, ttl: 1_800_000, // 30 minutes staleWhileRevalidate: 1_200_000, // 20 minutes async getFreshValue() { return prisma.userPrediction.findMany({ where: { tournamentId: tournament.id, challengeId: challenge ? challenge.id : null, }, orderBy: { score: 'desc' }, take: 10, include: { user: { select: { username: true } } }, }) }, })
Beta Was this translation helpful? Give feedback.
All reactions
-
Whoops! I made a mistake by removing the utility that made the cache multi-region safe. I've just pushed this commit to fix it: a1b3aa4
My apologies! Thank you for bringing it up.
As a note, you wouldn't want to use ensurePrimary
for this because so many requests result in a cache update that you'd pretty much never benefit from having multiple regions. So instead we trigger a request to the primary when the cache needs to be updated.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Ah, thanks!! I thought I was going crazy.
Beta Was this translation helpful? Give feedback.