std::ifstream ifs( CacheFile.c_str() );
boost::archive::xml_iarchive ia(ifs);
+ ip_map_type new_IpCache;
+ cname_map_type new_CnameCache;
std::string cache_save_time_str;
- ia & BOOST_SERIALIZATION_NVP(IpCache);
- ia & BOOST_SERIALIZATION_NVP(CnameCache);
+ ia & BOOST_SERIALIZATION_NVP(new_IpCache);
+ ia & BOOST_SERIALIZATION_NVP(new_CnameCache);
ia & BOOST_SERIALIZATION_NVP(cache_save_time_str);
- boost::posix_time::ptime cache_save_time
+ const boost::posix_time::ptime cache_save_time
= boost::posix_time::from_iso_string(cache_save_time_str);
GlobalLogger.info() << "DnsCache: loaded from file " << CacheFile;
+ // atomic switch over
+ IpCache.swap(new_IpCache);
+ CnameCache.swap(new_CnameCache);
+
check_timestamps(cache_save_time);
}
catch (boost::archive::archive_exception &exc)