{"record":{"id":"dec90cf0a1d3c4f2","repo":"diegosouzapw/OmniRoute","slug":"cache-size-change-did-not-take-effect-expected","errorCode":null,"errorMessage":"cache_size change did not take effect (expected ${targetCacheSize}, got ${newCacheSize})","messagePattern":"cache_size change did not take effect \\(expected (.+?), got (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/db/optimizationSettings.ts","lineNumber":165,"sourceCode":"\nexport function setCacheSizeForDb(db: SqliteDatabase, cacheSizeKb: number): void {\n  const normalizedCacheSizeKb = requireCacheSizeKb(cacheSizeKb);\n  const currentCacheSize = db.pragma(\"cache_size\", { simple: true }) as number;\n  const targetCacheSize = -normalizedCacheSizeKb;\n\n  if (currentCacheSize === targetCacheSize) {\n    console.log(`[DB] cache_size already set to ${normalizedCacheSizeKb}KB`);\n    return;\n  }\n\n  console.log(\n    `[DB] Changing cache_size from ${Math.abs(currentCacheSize)}KB to ${normalizedCacheSizeKb}KB`\n  );\n  db.pragma(`cache_size = ${targetCacheSize}`);\n\n  const newCacheSize = db.pragma(\"cache_size\", { simple: true }) as number;\n  if (newCacheSize !== targetCacheSize) {\n    throw new Error(\n      `cache_size change did not take effect (expected ${targetCacheSize}, got ${newCacheSize})`\n    );\n  }\n  console.log(`[DB] cache_size changed to ${Math.abs(newCacheSize)}KB`);\n}\n\nfunction applyPersistentOptimizationPragmas(\n  db: SqliteDatabase,\n  settings: DatabaseOptimizationSettings\n): void {\n  const targetAutoVacuum = AUTO_VACUUM_MODE_TO_PRAGMA[settings.autoVacuumMode];\n  const targetPageSize = normalizePageSizeBytes(\n    settings.pageSize,\n    DEFAULT_DATABASE_SETTINGS.optimization.pageSize\n  );\n  const currentAutoVacuum = db.pragma(\"auto_vacuum\", { simple: true }) as number;\n  const currentPageSize = db.pragma(\"page_size\", { simple: true }) as number;\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/optimizationSettings.ts#L147-L183","documentation":"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).","triggerScenarios":"Thrown at src/lib/db/optimizationSettings.ts:165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the active SQLite driver supports pragma cache_size writes (some adapters ignore it)","Check the connection is not read-only or in a transaction that defers pragma application","Re-apply the setting after reconnecting, or log a warning and keep the previous cache size"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}