Can I adjust the memory cache size differently for different databases?

caching, sqlite

Solution

`PRAGMA cache_size` affects only one database connection.

Ensure that your connections are not shared (with `sqlite3_enable_shared_cache` or `SQLITE_OPEN_SHAREDCACHE`).

Problem

I have an application that uses SQLite. It uses seven different database files, each with a connection created with `sqlite3_open`. Six of these aren't performance critical, but one is. I'd like to increase the memory caching on the performance-critical database connection using `PRAGMA cache_size`. However, this changes the cache size for all connections. I don't have enough memory for each of the seven databases to use as much memory as I need the performance-critical one to use. I've confirmed that the setting does affect all connections. And I've confirmed that there's no common pool -- each connection is individually limited to the specified memory amount. Is there a simple workaround?

Original source