Index: whois.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/whois/whois.admin.inc,v retrieving revision 1.3 diff -u -p -r1.3 whois.admin.inc --- whois.admin.inc 19 Jan 2010 15:02:59 -0000 1.3 +++ whois.admin.inc 1 Feb 2010 08:27:21 -0000 @@ -40,12 +40,40 @@ function whois_settings() { '#default_value' => variable_get('whois_hourly_threshold', 13), '#description' => t('The maximum number of whois lookups a user can perform per hour.'), ); - $form['whois_log_watchdog'] = array( + $form['whois_log'] = array( + '#type' => 'fieldset', + '#title' => t('Lookup log'), + '#description' => t('Log whois lookups. Log available as a block or a table at admin/reports/whois.'), + ); + $form['whois_log']['whois_log_watchdog'] = array( '#type' => 'checkbox', '#title' => t('Log watchdog entry'), '#default_value' => variable_get('whois_log_watchdog', 1), '#description' => t('Log a watchdog entry for each whois lookup performed.'), ); + $form['whois_log']['whois_log_watchdog_cached'] = array( + '#type' => 'checkbox', + '#title' => t('Log watchdog entry for cached domains also'), + '#default_value' => variable_get('whois_log_watchdog_cached', 0), + '#description' => t('Log a watchdog entry for each whois lookup performed even if it is cached.'), + ); + $form['whois_cache'] = array( + '#type' => 'fieldset', + '#title' => t('Cache configuration'), + '#collapsed' => TRUE, + ); + $form['whois_cache']['whois_cache_enable'] = array( + '#type' => 'checkbox', + '#title' => t('Enable cache'), + '#default_value' => variable_get('whois_cache_enable', 1), + '#description' => t('Enable the caching of whois records.'), + ); + $form['whois_cache']['whois_cache_time'] = array( + '#type' => 'textfield', + '#title' => t('Cache time'), + '#default_value' => variable_get('whois_cache_time', 86400), + '#description' => t('The length of time in seconds to cache whois lookup results. Set to "0" to never expire cached entries.'), + ); return system_settings_form($form); } Index: whois.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/whois/whois.module,v retrieving revision 1.22 diff -u -p -r1.22 whois.module --- whois.module 29 Jan 2010 13:56:08 -0000 1.22 +++ whois.module 1 Feb 2010 08:27:21 -0000 @@ -217,17 +217,36 @@ function whois_get_whois($address) { } elseif ($address != '') { $address = _whois_cleanup_address($address); - include_once($mod_path . '/phpwhois/whois.main.php'); - include_once($mod_path . '/phpwhois/whois.utils.php'); - $whois = new Whois(); - if (variable_get('whois_log_watchdog', 1)) { - // Watchdog entry for lookup request. - watchdog('whois', - 'Whois lookup for: %address', - array('%address' => $address), - WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/")); - } - $result = $whois->Lookup($address); + // check cache first + $cid = 'whois-' . $address; + if (variable_get('whois_cache_enable', 1) && ($cache = cache_get($cid, "cache")) && !empty($cache->data)) { + if (variable_get('whois_log_watchdog', 1) && variable_get('whois_log_watchdog_cached', 0) ) { + // Watchdog entry for lookup request if logging cached lookup also. + watchdog('whois', + 'Whois lookup for: @address', + array('@address' => $address), + WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/")); + } + return $cache->data; + } + else { + include_once($mod_path . '/phpwhois/whois.main.php'); + include_once($mod_path . '/phpwhois/whois.utils.php'); + $whois = new Whois(); + if (variable_get('whois_log_watchdog', 1)) { + // Watchdog entry for lookup request. + watchdog('whois', + 'Whois lookup for: %address', + array('%address' => $address), + WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/")); + } + $result = $whois->Lookup($address); + + // cache results + if (variable_get('whois_cache_enable', 1) && !empty($result)) { + cache_set($cid, $result, "cache", variable_get("whois_cache_time", 86400)); + } + if (empty($result) || empty($result['rawdata'])) { $result['error_query'] = $whois->Query; }