saveToDisk

Writes the cache to disk if anything changed since the last write.

Called from the periodic task and at shutdown. Skipping a clean cache matters because the task fires on a fixed interval whether or not anyone chatted.

A failed write leaves the previous file untouched: a cache that does not parse is discarded wholesale on the next boot, so a torn file costs every entry accumulated so far.