#include <fstream>
 #include <logfunc.hpp>
 #include <filefunc.hxx>   // I2n::file_exists
+#include <tmpfstream.hpp>
 #include <boost/foreach.hpp>
 #include <boost/bind.hpp>
 #include <boost/asio/placeholders.hpp>
             std::string cache_save_time_str = boost::posix_time::to_iso_string(
                             boost::posix_time::second_clock::universal_time() );
 
-            std::ofstream ofs( CacheFile.c_str() );
+            I2n::tmpofcopystream ofs( CacheFile.c_str() );
             boost::archive::xml_oarchive oa(ofs);
             oa & BOOST_SERIALIZATION_NVP(IpCache);
             oa & BOOST_SERIALIZATION_NVP(CnameCache);