Skip to content

In-memory Databases And Shared Cache #97

Answered by ncruces
ncruces asked this question in Q&A
Discussion options

You must be logged in to vote

Shared cache use is discouraged, SQLITE_OMIT_SHARED_CACHE is recommended.

The increasingly recommended alternative is to use the memdb VFS, which we do support.

So instead of:

db, err := sql.Open("sqlite3", "file:data.db?mode=memory&cache=shared")

Do:

import _ "github.com/ncruces/go-sqlite3/vfs/memdb"db, err := sql.Open("sqlite3", "file:/data.db?vfs=memdb")

The slash / in the name is important, as that makes it a shared database!

This is especially useful for tests. Using shared cache with any concurrency requires using unlock notifications to handle SQLITE_LOCKED, whereas "normal" connections require a busy handler to handle SQLITE_BUSY. If you use shared cache in-memory databases, yo…

Replies: 1 comment

Comment options

ncruces
Jun 11, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by ncruces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
1 participant