On Sep 11, 2010, at 9:19 AM, Sam Carleton wrote: > I just read the page on Shared-Cache Mode and it left me with some > questions... > > Q1: Is my understanding correct: Shared-Cache Mode is used within a > process to gain table locking, as compared to the normal file locking.
Fair enough. That's not the reason it was added, but that is one use for shared-cache mode. You will get table-level locking within a process if you enable shared-cache mode. Shared-cache mode was added to save memory on embedded platforms. If you're not specifically worried about memory, and not using the unlock-notify feature, WAL mode gives you more concurrency these days anyhow. http://www.sqlite.org/unlock_notify.html http://www.sqlite.org/wal.html > How to Enabling Shared-Cache Mode in the following situation: > > SQLite is being used in an Apache module which uses the Apache DBD > API. The DBD is a connection pooling API. In other words, the DBD > calls sqlite3_open_v2() and the module simply gets a connections from > the DBD. Before the module code ever gets executed, the DBD creates 4 > connections to the database. > > Q2: Is my understanding correct: The first time the module code gets > a connection and calls int sqlite3_enable_shared_cache(int), the other > three connections will NOT be in the Shared-Cache, but any future > connections will be in the shared-cache. > > Q3: Further, when the module code gets the second connection and calls > int sqlite3_enable_shared_cache(int), it will be added to the same > shared-cache. All that matters is whether or not shared-cache mode is enabled when sqlite3_open[_v2]() is called (or when the database is ATTACHed, if it is an attached db). If shared-cache mode is enabled at this point, the connection will be able to connect to an existing shared-cache (if one exists), or create a new cache that connections opened in the future may share. If it is not enabled when sqlite3_open[_v2]() is called, the connection uses a private cache. > Q4: My thought is each and every time the module code gets a > connection, it simply calls int sqlite3_enable_shared_cache(int) to > make sure that connection is in the shared-pool. Am I correct in > assuming that the cost of calling int sqlite3_enable_shared_cache(1) > when shared-cache is already enabled is very small? Very small. Dan. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users