Index: whois.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/whois/whois.install,v
retrieving revision 1.2
diff -u -r1.2 whois.install
--- whois.install	12 Aug 2008 14:53:56 -0000	1.2
+++ whois.install	9 Jan 2009 04:57:12 -0000
@@ -5,8 +5,27 @@
  * Implementation of hook_uninstall().
  */
 function whois_uninstall() {
+  drupal_uninstall_schema('whois');
+  variable_del('whois_store_data');
+  variable_del('whois_cache_time');
   variable_del('whois_output_method');
   variable_del('whois_enable_ajax');
   variable_del('whois_hourly_threshold');
   variable_del('whois_log_watchdog');
 }
+
+function whois_install() {
+  drupal_install_schema('whois');
+}
+
+function whois_schema() {
+  $schema['whois_data'] = array(
+    'fields' => array(
+         'address' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
+         'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
+         'data' => array('type' => 'blob', 'not null' => TRUE)),
+    'primary key' => array('address', 'timestamp'),
+  );
+  
+  return $schema;
+}
\ No newline at end of file
Index: whois.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/whois/whois.module,v
retrieving revision 1.3
diff -u -r1.3 whois.module
--- whois.module	12 Aug 2008 11:15:57 -0000	1.3
+++ whois.module	8 Jan 2009 04:57:56 -0000
@@ -85,6 +85,18 @@
     '#default_value' => variable_get('whois_hourly_threshold', 13),
     '#description' => t('The maximum number of whois lookups a user can perform per hour.'),
   );
+  $form['whois_settings']['whois_store_data'] = array('#type' => 'radios',
+    '#title' =>t('Store WHOIS data'),
+    '#options' => array('False', 'True'),
+    '#default_value' => variable_get('whois_store_data', 0),
+    '#description' => t('Choose whether to store the WHOIS result in the database for historic tracking or caching'),
+  );
+  $form['whois_settings']['whois_cache_time'] = array('#type' => 'select',
+    '#title' => t('Cache time'),
+    '#options' => array(0=>'No Caching', 3600=>'1 hour', 43200=>'12 hours', 86400=>'24 hours', 604800=>'1 week', 1209600=>'14 days', 2592000=>'30 days'),
+    '#default_value' => variable_get('whois_cache_time', 0),
+    '#description' => t('Cache time is useful when the data is stored.  Use a cache time to return the stored response for a certain time period to prevent repeated queries to the WHOIS server.  NOTE: if there is not a cache time and the data is stored, the WHOIS data table may grow very large, as each query will be stored.'),
+  );
   $form['whois_log_watchdog'] = array(
     '#type' => 'checkbox',
     '#title' => t('Log watchdog entry'),
@@ -185,8 +197,27 @@
     include_once('phpwhois/whois.main.php');
     include_once('phpwhois/whois.utils.php');
     $option = variable_get('whois_output_method', 'html');
+
+    //See if we are storing the data, as well as if we should return a cached response.
+    $store_whois = variable_get('whois_store_data', FALSE);
+    $cache_whois_time = variable_get('whois_cache_time', 0);
+    
+    if ($store_whois) {
+      //Check to see if there is WHOIS data stored in the database.
+      $cached_data = db_result(db_query("SELECT data FROM {whois_data} WHERE address = '%s' AND timestamp >= UNIX_TIMESTAMP() - %d", $address, $cache_whois_time));
+      if ($cached_data) {
+        $result = unserialize($cached_data);
+      }
+    }
+    
     $whois = new Whois();
-    $result = $whois->Lookup($address);
+    if (!$result) {
+      $result = $whois->Lookup($address);
+      //Store the result if necessary
+      if ($store_whois) {
+        db_query("INSERT INTO {whois_data} (address, timestamp, data) VALUES ('%s', %d, '%s')", $address, time(), serialize($result));
+      }
+    }
 
     switch($option) {
       case 'html':

