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
Fix double commit on staged writes

- Detect double commit as an illegal state
- Remove double commit in component cache
Clean up staged write and tests
Merge pull request #542 from elehack/feature/elehack-cache-io

Add helper for staged file writes