Replies: 2 comments
-
I see where you're coming from. Sync APIs are definitely convenient, especially when working with SQLite in Node, Bun, or Deno, but caching them isn't straightforward due to the nature of the JavaScript event loop. Since sync functions block the main thread, most caching layers (which rely on async IO) don’t integrate naturally. That said, a few workarounds might help: In-memory caching
Worker threads (Node.js) As for native sync caching APIs: it’s unlikely the runtimes will add support for this anytime soon, mainly due to the complexity and limitations around sync execution in JS environments. Still, it might be worth exploring at the library level for SQLite wrappers. |
Beta Was this translation helpful? Give feedback.
-
What do you mean? You'll likely need to wrap the db access anyway, to validate if the access is allowed. Anyway, you can wrap the call in an async function. const getUserByUsername = database.prepare(`
SELECT * FROM users WHERE username = ?
`);
async function readUsername(username) {
'use cache'
return getUserByUsername.get(username)
} Something like that - I know some linters, etc, might say, well this is unnecessarily asynchronous, but that can be worked around too. Also you can cache at different levels, you might want to cache the entire page result, if all you want is to produce a static shell that uses the data from the sqlite query, not just specific functions. You might want to also cache only for this render pass, with React.cache. What is your use case? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
Proposal
Beta Was this translation helpful? Give feedback.
All reactions