New cache_size_kb config for SQLite, closes #304

This commit is contained in:
Simon Willison 2018-06-04 09:02:07 -07:00
commit 29edbe90ff
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
4 changed files with 33 additions and 0 deletions

View file

@ -90,6 +90,9 @@ CONFIG_OPTIONS = (
ConfigOption("default_cache_ttl", 365 * 24 * 60 * 60, """
Default HTTP cache TTL (used in Cache-Control: max-age= header)
""".strip()),
ConfigOption("cache_size_kb", 0, """
SQLite cache size in KB (0 == use SQLite default)
""".strip()),
)
DEFAULT_CONFIG = {
option.name: option.default
@ -238,6 +241,8 @@ class Datasette:
conn.enable_load_extension(True)
for extension in self.sqlite_extensions:
conn.execute("SELECT load_extension('{}')".format(extension))
if self.config["cache_size_kb"]:
conn.execute('PRAGMA cache_size=-{}'.format(self.config["cache_size_kb"]))
pm.hook.prepare_connection(conn=conn)
def inspect(self):