Add pragmas, hard_reset, and vacuum for tuning disk-backed caches
This commit is contained in:
@@ -385,3 +385,39 @@ def test_two_engines_separate_cache_files(source_engine, tmp_path):
|
||||
assert b._cache.is_table_cached("products") is False # independent cache
|
||||
a.close()
|
||||
b.close()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Pragmas / hard_reset / vacuum (1.11.0)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_engine_passes_pragmas_to_cache(source_engine, tmp_path):
|
||||
ce = CachingEngine(
|
||||
source_engine,
|
||||
cache_db_path=tmp_path / "cache.db",
|
||||
in_memory=False,
|
||||
pragmas={"page_size": 8192, "auto_vacuum": "INCREMENTAL"},
|
||||
)
|
||||
assert ce._cache.connection.execute("PRAGMA page_size").fetchone()[0] == 8192
|
||||
assert ce._cache.connection.execute("PRAGMA auto_vacuum").fetchone()[0] == 2
|
||||
ce.close()
|
||||
|
||||
|
||||
def test_engine_hard_reset_reloads(source_engine, tmp_path):
|
||||
ce = CachingEngine(source_engine, cache_db_path=tmp_path / "cache.db", in_memory=False)
|
||||
ce.execute("SELECT id FROM products")
|
||||
assert ce._cache.is_table_cached("products") is True
|
||||
|
||||
ce.hard_reset()
|
||||
assert ce._cache.is_table_cached("products") is False
|
||||
rows = ce.execute("SELECT id, name FROM products") # reloads on next use
|
||||
assert len(rows) == 3
|
||||
ce.close()
|
||||
|
||||
|
||||
def test_engine_vacuum_runs(source_engine, tmp_path):
|
||||
ce = CachingEngine(source_engine, cache_db_path=tmp_path / "cache.db", in_memory=False)
|
||||
ce.execute("SELECT id FROM products")
|
||||
ce.vacuum(incremental=False) # must not raise
|
||||
assert ce._cache.is_table_cached("products") is True
|
||||
ce.close()
|
||||
|
||||
Reference in New Issue
Block a user