namespace Config
{
const int SAVE_TIMER_SECONDS = 60;
- const int CACHE_TIME_WARP_THRESH_HOURS = 24;
+ const int CACHE_TIME_WARP_THRESH_MINS = 10;
const int CACHE_REMOVE_OUTDATED_DAYS = 60;
}
// check if CacheSaveTime is in the future
boost::posix_time::ptime now
= boost::posix_time::second_clock::universal_time()
- + boost::posix_time::hours( Config::CACHE_TIME_WARP_THRESH_HOURS );
+ + boost::posix_time::minutes(Config::CACHE_TIME_WARP_THRESH_MINS);
if (now > cache_save_time)
{ // Cache was saved in the past -- everything alright
return false;
<< cache_save_time << ")! Resetting all TTLs to 0.";
// reset TTLs in IP cache
- BOOST_FOREACH( const ip_map_type::value_type key_and_ip, IpCache )
+ BOOST_FOREACH( ip_map_type::value_type &key_and_ip, IpCache )
{
- HostAddressVec addr_reset;
- BOOST_FOREACH( HostAddress address, key_and_ip.second )
- addr_reset.push_back( HostAddress( address.get_ip(), 0 ) );
- IpCache[key_and_ip.first] = addr_reset;
+ BOOST_FOREACH( HostAddress &address, key_and_ip.second )
+ address.get_ttl().set_value(0);
}
// reset TTLs in CNAME cache
- BOOST_FOREACH( const cname_map_type::value_type key_and_cname, CnameCache )
- CnameCache[key_and_cname.first] = Cname( key_and_cname.second.Host,
- TimeToLive(0) );
+ BOOST_FOREACH( cname_map_type::value_type &key_and_cname, CnameCache )
+ key_and_cname.second.Ttl.set_value(0);
+
+ HasChanged = true;
+
+ //debug_print();
return true;
}
- boost::gregorian::days( Config::CACHE_REMOVE_OUTDATED_DAYS );
// IP cache
- bool some_ip_up_to_date;
- BOOST_FOREACH( const ip_map_type::value_type key_and_ip, IpCache )
{
- some_ip_up_to_date = false;
- BOOST_FOREACH( HostAddress address, key_and_ip.second )
+ ip_map_type::iterator it = IpCache.begin();
+ ip_map_type::iterator it_end = IpCache.end();
+ bool some_ip_up_to_date;
+ while (it != it_end)
{
- if ( ! address.get_ttl().was_set_before(thresh) )
+ some_ip_up_to_date = false;
+ BOOST_FOREACH( const HostAddress &address, (*it).second )
{
- some_ip_up_to_date = true;
- break;
+ if ( ! address.get_ttl().was_set_before(thresh) )
+ {
+ some_ip_up_to_date = true;
+ break;
+ }
}
- }
- if ( ! some_ip_up_to_date )
- {
- GlobalLogger.debug() << "DnsCache: Removing empty/outdated IP list "
- << "for " << key_and_ip.first.first;
- IpCache.erase( key_and_ip.first );
+ if ( ! some_ip_up_to_date )
+ {
+ GlobalLogger.debug() << "DnsCache: Removing empty/outdated IP "
+ << "list for " << (*it).first.first;
+ IpCache.erase( (*it++).first );
+ }
+ else
+ ++it;
}
}
// CNAME cache
- BOOST_FOREACH( const cname_map_type::value_type key_and_cname, CnameCache )
{
- if ( key_and_cname.second.Ttl.was_set_before( thresh ) )
+ cname_map_type::iterator it = CnameCache.begin();
+ cname_map_type::iterator it_end = CnameCache.end();
+ while (it != it_end)
{
- GlobalLogger.debug() << "DnsCache: Removing outdated CNAME for "
- << key_and_cname.first;
- CnameCache.erase( key_and_cname.first );
+ if ( (*it).second.Ttl.was_set_before( thresh ) )
+ {
+ GlobalLogger.debug() << "DnsCache: Removing outdated CNAME for "
+ << (*it).first;
+ CnameCache.erase( (*it++).first );
+ }
+ else
+ ++it;
}
}
}
}
return temp.str();
}
+
+
+// -----------------------------------------------------------------------------
+// OTHER
+// -----------------------------------------------------------------------------
+void DnsCache::debug_print() const
+{
+ GlobalLogger.debug() << "DnsCache: IP Cache contents:";
+ stringstream log_temp;
+ BOOST_FOREACH( const ip_map_type::value_type &key_and_ip, IpCache )
+ {
+ // write IPs into one log line
+ log_temp.str("");
+ log_temp << "DnsCache: " << key_and_ip.first.first << ": \t "
+ << key_and_ip.second.size() << "-list ";
+ BOOST_FOREACH( const HostAddress &ip, key_and_ip.second )
+ log_temp << ip.get_ip() << "+" << ip.get_ttl().get_updated_value()
+ << "s, ";
+ GlobalLogger.debug() << log_temp.str();
+ }
+
+ GlobalLogger.debug() << "DnsCache: CNAME Cache contents:";
+ BOOST_FOREACH( const cname_map_type::value_type &key_and_cname, CnameCache )
+ GlobalLogger.debug() << "DnsCache: " << key_and_cname.first << ": \t "
+ << key_and_cname.second.Host << "+"
+ << key_and_cname.second.Ttl.get_updated_value()
+ << "s";
+}