{"record":{"id":"c20c4ec742b59b56","repo":"pentaho/pentaho-kettle","slug":"we-can-t-write-to-the-cache-file","errorCode":null,"errorMessage":"We can't write to the cache file: ","messagePattern":"We can't write to the cache file: ","errorType":"exception","errorClass":"KettleFileException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/DBCache.java","lineNumber":198,"sourceCode":"\n          int counter = 0;\n\n          for ( DBCacheEntry entry : cache.keySet() ) {\n            entry.write( dos );\n\n            // Save the corresponding row as well.\n            RowMetaInterface rowMeta = get( entry );\n            if ( rowMeta != null ) {\n              rowMeta.writeMeta( dos );\n              counter++;\n            } else {\n              throw new KettleFileException( \"The database cache contains an empty row. We can't save this!\" );\n            }\n          }\n          log.logDetailed( \"We wrote \" + counter + \" cached rows to the database cache!\" );\n        }\n      } else {\n        throw new KettleFileException( \"We can't write to the cache file: \" + filename );\n      }\n    } catch ( Exception e ) {\n      throw new KettleFileException( \"Couldn't write to the database cache\", e );\n    }\n  }\n\n  /**\n   * Create the database cache instance by loading it from disk\n   *\n   * @return the database cache instance.\n   */\n  @SuppressWarnings( \"squid:S00112\" )\n  public static DBCache getInstance() {\n    if ( dbCache != null ) {\n      return dbCache;\n    }\n    try {\n      dbCache = new DBCache();","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/DBCache.java#L180-L216","documentation":"saveCache() first creates/opens the cache file for writing; if the file object is not writable (doesn't exist and can't be created, or is read-only) it throws KettleFileException 'We can't write to the cache file: <filename>', naming the file. This happens before any cache content is serialized.","triggerScenarios":"Calling savesCacheToDisk()/saveCache() when the cache file path exists but is not writable, the parent directory doesn't exist, or the file is locked by another process.","commonSituations":"Read-only Kettle installation directory or KETTLE_SYSTEM_DIR; running multiple Kettle instances concurrently locking db.cache; running under a service account lacking write permissions to the cache folder.","solutions":["Verify the cache file's directory exists and the process user has write permission; chmod/chown or move KETTLE home to a writable location","Close other running Kettle instances or delete stale locks on db.cache","Disable the DB cache (e.g. KETTLE_CURSOR / cache size 0 options) if the environment must be read-only"],"exampleFix":"// before\nFile cache = new File(filename); // in read-only dir\nsaveCache();\n// after\nFile f = new File(filename);\nif (!f.canWrite()) { log.logBasic(\"Skipping DB cache write, file not writable: \" + filename); return; }\nsaveCache();","handlingStrategy":"validation","validationCode":"File f = new File(cacheFile);\nFile dir = f.getParentFile();\nboolean ok = dir != null && dir.isDirectory() && dir.canWrite() && (!f.exists() || f.canWrite());\nif (!ok) { /* skip cache write or fix permissions */ }","typeGuard":null,"tryCatchPattern":"try { cache.savesCacheToDisk(); } catch (KettleFileException e) { if (e.getMessage().contains(\"can't write to the cache file\")) { log.warn(\"Cache file not writable: \" + e.getMessage()); } else { throw e; } }","preventionTips":["Ensure the Kettle home/system directory is writable by the service user","Avoid running multiple Kettle instances sharing one cache file","Point KETTLE_HOME to a writable location on read-only installs","Consider disabling the DB cache in read-only environments"],"tags":["file-write","cache","permissions","pentaho-kettle"],"backgroundTag":"file-write-permission-denied","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}