SQLite Connection 是否需要保持打开(连接)状态才能利用 Pragma Cache_size?
Does SQLite Connection needs to remain open(connected) to take advantage of Pragma Cache_size?
我一直认为管理数据库连接的最佳实践是连接到它,执行查询并立即关闭数据库连接
但是,对于 SQlite,我在他们的网站上偶然发现了以下关于 PRAGMA 的片段 CACHE_SIZE
来自 SQlite Website
PRAGMA cache_size; PRAGMA cache_size = pages; PRAGMA cache_size =
-kibibytes;
Query or change the suggested maximum number of database disk pages
that SQLite will hold in memory at once per open database file.
Whether or not this suggestion is honored is at the discretion of the
Application Defined Page Cache. The default page cache that is built
into SQLite honors the request, however alternative
application-defined page cache implementations may choose to interpret
the suggested cache size in different ways or to ignore it all
together. The default suggested cache size is 2000 pages.
If the argument N is positive then the suggested cache size is set to
N. If the argument N is negative, then the number of cache pages is
adjusted to use approximately N*1024 bytes of memory. Backwards
compatibility note: The behavior of cache_size with a negative N was
different in SQLite versions prior to 3.7.10. In version 3.7.9 and
earlier, the number of pages in the cache was set to the absolute
value of N.
When you change the cache size using the cache_size pragma, the change
only endures for the current session. The cache size reverts to the
default value when the database is closed and reopened.
这是否意味着我要从内存缓存中受益,我需要在整个应用程序期间保持与 SQLite 数据库文件的连接?在我断开数据库连接的那一刻,所有缓存内存都丢失了?
关闭连接时确实丢弃了缓存。
在 SQLite 和所有其他数据库中,打开连接都有一些开销。
使用许多短期连接绝不是一个好主意。
在您确实有许多独立的、短暂的工作(例如 Web 服务器)的情况下,您通常会通过使用连接池来解决这些低效问题。
我一直认为管理数据库连接的最佳实践是连接到它,执行查询并立即关闭数据库连接
但是,对于 SQlite,我在他们的网站上偶然发现了以下关于 PRAGMA 的片段 CACHE_SIZE 来自 SQlite Website
PRAGMA cache_size; PRAGMA cache_size = pages; PRAGMA cache_size = -kibibytes;
Query or change the suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file. Whether or not this suggestion is honored is at the discretion of the Application Defined Page Cache. The default page cache that is built into SQLite honors the request, however alternative application-defined page cache implementations may choose to interpret the suggested cache size in different ways or to ignore it all together. The default suggested cache size is 2000 pages.
If the argument N is positive then the suggested cache size is set to N. If the argument N is negative, then the number of cache pages is adjusted to use approximately N*1024 bytes of memory. Backwards compatibility note: The behavior of cache_size with a negative N was different in SQLite versions prior to 3.7.10. In version 3.7.9 and earlier, the number of pages in the cache was set to the absolute value of N.
When you change the cache size using the cache_size pragma, the change only endures for the current session. The cache size reverts to the default value when the database is closed and reopened.
这是否意味着我要从内存缓存中受益,我需要在整个应用程序期间保持与 SQLite 数据库文件的连接?在我断开数据库连接的那一刻,所有缓存内存都丢失了?
关闭连接时确实丢弃了缓存。
在 SQLite 和所有其他数据库中,打开连接都有一些开销。 使用许多短期连接绝不是一个好主意。
在您确实有许多独立的、短暂的工作(例如 Web 服务器)的情况下,您通常会通过使用连接池来解决这些低效问题。