diegosouzapw/OmniRoute · error

cache_size change did not take effect

Error message

cache_size change did not take effect (expected ${targetCacheSize}, got ${newCacheSize})

What it means

Post-change verification in setCacheSizeForDb: after issuing PRAGMA cache_size = -<targetKiB>, re-reading the pragma returned a value different from the requested one, meaning the driver/database did not apply the setting (unsupported pragma behavior, read-only connection, or driver quirk).

Solutions

  1. Verify the active SQLite driver supports pragma cache_size writes (some adapters ignore it)
  2. Check the connection is not read-only or in a transaction that defers pragma application
  3. Re-apply the setting after reconnecting, or log a warning and keep the previous cache size
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/db/optimizationSettings.ts:165 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/dec90cf0a1d3c4f2. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/optimizationSettings.ts:165

export function setCacheSizeForDb(db: SqliteDatabase, cacheSizeKb: number): void {
  const normalizedCacheSizeKb = requireCacheSizeKb(cacheSizeKb);
  const currentCacheSize = db.pragma("cache_size", { simple: true }) as number;
  const targetCacheSize = -normalizedCacheSizeKb;

  if (currentCacheSize === targetCacheSize) {
    console.log(`[DB] cache_size already set to ${normalizedCacheSizeKb}KB`);
    return;
  }

  console.log(
    `[DB] Changing cache_size from ${Math.abs(currentCacheSize)}KB to ${normalizedCacheSizeKb}KB`
  );
  db.pragma(`cache_size = ${targetCacheSize}`);

  const newCacheSize = db.pragma("cache_size", { simple: true }) as number;
  if (newCacheSize !== targetCacheSize) {
    throw new Error(
      `cache_size change did not take effect (expected ${targetCacheSize}, got ${newCacheSize})`
    );
  }
  console.log(`[DB] cache_size changed to ${Math.abs(newCacheSize)}KB`);
}

function applyPersistentOptimizationPragmas(
  db: SqliteDatabase,
  settings: DatabaseOptimizationSettings
): void {
  const targetAutoVacuum = AUTO_VACUUM_MODE_TO_PRAGMA[settings.autoVacuumMode];
  const targetPageSize = normalizePageSizeBytes(
    settings.pageSize,
    DEFAULT_DATABASE_SETTINGS.optimization.pageSize
  );
  const currentAutoVacuum = db.pragma("auto_vacuum", { simple: true }) as number;
  const currentPageSize = db.pragma("page_size", { simple: true }) as number;

View on GitHub (pinned to a179ffed5b)