write to disk only when shutting down to preserve cache