Index: whois.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/whois/whois.admin.inc,v
retrieving revision 1.3
diff -u -r1.3 whois.admin.inc
--- whois.admin.inc	19 Jan 2010 15:02:59 -0000	1.3
+++ whois.admin.inc	2 Feb 2010 12:00:43 -0000
@@ -40,12 +40,40 @@
     '#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.20.2.2
diff -u -r1.20.2.2 whois.module
--- whois.module	29 Jan 2010 13:55:19 -0000	1.20.2.2
+++ whois.module	2 Feb 2010 12:00:44 -0000
@@ -142,7 +142,13 @@
     switch (variable_get('whois_output_method', 'html')) {
       case 'html':
         $data .= '<h3>' . t('Whois lookup for %address:', array('%address' => $address)) . '</h3>';
+        if (!empty($result['whois_cached_on'])) {
+          $data .= "<p id='whois_cached_on'>" . t('Cached on:') . ' ' . format_date($result['whois_fetched'], 'large') . "</p>";
+        }
         if (!empty($result['rawdata'])) {
+          $mod_path = drupal_get_path('module', 'whois');
+          include_once($mod_path . '/phpwhois/whois.main.php');
+          include_once($mod_path . '/phpwhois/whois.utils.php');
           $utils = new utils;
           $data .= filter_xss(_whois_utf8_encode($utils->showHTML($result), $address), $allowed_tags);
         }
@@ -166,6 +172,9 @@
           $data .= _whois_handle_error($result, $address);
         }
         else {
+          $mod_path = drupal_get_path('module', 'whois');
+          include_once($mod_path . '/phpwhois/whois.main.php');
+          include_once($mod_path . '/phpwhois/whois.utils.php');
           $utils = new utils;
           $data .= '<pre>' . filter_xss(_whois_utf8_encode($utils->showObject($result), $address), $allowed_tags) . '</pre>';
         }
@@ -205,24 +214,42 @@
   }
   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/"));
+    // 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(cached) for: @address',
+          array('@address' => $address),
+          WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/"));
+      }
+      $cache->data['whois_cached_on'] = $cache->created;
+      return $cache->data;
     }
-    $result = $whois->Lookup($address);
-    if (empty($result) || empty($result['rawdata'])) { 
-      $result['error_query'] = $whois->Query;
+    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);
+
+
+      if (empty($result) || empty($result['rawdata'])) { 
+        $result['error_query'] = $whois->Query;
+      }
+      elseif (variable_get('whois_cache_enable', 1)) {
+        // cache results
+        cache_set($cid, $result, "cache", variable_get("whois_cache_time", 86400));
+      }
+      return $result;
     }
-    // Some debugging lines
-    //drupal_set_message(print_r($whois, true));
-    //drupal_set_message('result:' . print_r($result, true));
-    return $result; 
   }
   return FALSE;
 }
