SQLite 共享缓存数据库

SQLite Shared Cache Database

我使用以下代码创建了一个共享内存数据库,但问题是,即使我关闭连接或重新启动机器,数据仍然可用。

我不明白数据是如何持久化的以及它的物理存储位置。

using (SQLiteConnection database = new SQLiteConnection("file: empDB ? mode = memory & cache = shared"))
            {
                database.CreateTable(emp.GetType());
                database.Insert(emp);
                var value = database.Query<Emp>("select * from emp;select * from emp;");
            }

要实现预期的行为,您可以使用 FullUri 语法,例如:

using (SQLiteConnection database = new SQLiteConnection("FullUri=file:empDB?mode=memory&cache=shared"))
{
  database.Open();
  // ....
}

I didn't understand how the data is persistent and where it is physically stored.

名称为 empDB 的数据库文件是在您使用原始连接字符串时在您的应用程序工作目录中创建的,例如FullUri=file: empDB ? mode = memory & cache = shared。当您再次 运行 应用程序时,将重新使用此文件。