--- revenue_sharing_basic.module	Wed Feb 20 23:53:48 2008
+++ revenue_sharing_basic.module	Sun Mar 02 15:35:06 2008
@@ -12,6 +12,18 @@
 define('REVENUE_SHARING_BASIC_ERROR_PROFILE_NOT_ENABLED',   2);
 define('REVENUE_SHARING_BASIC_ERROR_NOT_CONFIGURED',        3);
 
+function revenue_sharing_basic_init() {
+  $last_refresh = variable_get(REVENUE_SHARING_LAST_REFRESH, 0);
+  $interval = variable_get(REVENUE_SHARING_REFRESH_INTERVAL, 0);
+
+  if ($interval) {
+     if (time() > ($last_refresh + $interval)) {
+       cache_clear_all('adsense', 'cache', TRUE);
+       variable_set(REVENUE_SHARING_LAST_REFRESH, time());
+     }
+   }
+}
+
 function revenue_sharing_basic_adsense($op, $args = array()) {
   switch ($op) {
     case 'status' :
@@ -89,8 +101,18 @@
     '#title'         => t('Enable revenue sharing'),
     '#return_value'  => 1,
     '#default_value' => variable_get(REVENUE_SHARING_BASIC_ENABLE, 0),
-    '#description'   => t('Note that enabling this will disable AdSense code caching, which can cause more resource usage for busy sites. The referral feature requires the referral module to be installed.')
+    '#description'   => t('Note that revenue sharing does not work reliably when cache is enabled. Disabling cache guarantees that each page view gets a chance of revenue sharing, but can cause more resource usage for busy sites. Alternatively you can force cache flush every certain number of minutes. See the option below for this.').'<br />'.t('The referral feature requires the referral module to be installed.')
     );
+  
+  $period = drupal_map_assoc(array(0, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600), 'format_interval');
+  $period[0] = t('none');
+  $form['revenue'][REVENUE_SHARING_REFRESH_INTERVAL] = array(
+    '#type'          => 'select',
+    '#title'         => t('Enforce periodic refresh of revenue sharing'),
+    '#default_value' => variable_get(REVENUE_SHARING_REFRESH_INTERVAL, 0),
+    '#options' => $period,
+    '#description'   => t('If Adsense caching is enabled, and you have revenue sharing as well, you may want to cause a periodic "roll of the dice" for page views. By doing so, the adsense cache will be flushed every X minutes, and a chance of changing the Google Adsense ID per the revenue sharing settings.')
+    );    
 
   $form['revenue'][REVENUE_SHARING_BASIC_PERCENTAGE_AUTHOR] = array(
     '#type'          => 'select',
