Implement StagedWrite helper class
Improve component cache IO logic

- Write to temporary file first, so existing files are complete
- Automatically ignore (with warning) corrupted cache entries
Use StagedWrite in the pack task