Index: tagadelic.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tagadelic/tagadelic.module,v
retrieving revision 1.36.2.3
diff -u -p -r1.36.2.3 tagadelic.module
--- tagadelic.module	13 Mar 2007 09:58:31 -0000	1.36.2.3
+++ tagadelic.module	17 Aug 2007 19:01:03 -0000
@@ -95,6 +95,16 @@ function tagadelic_settings() {
     '#default_value' => variable_get('tagadelic_levels', 6),
     '#description' => t('The number of levels between the least popular tags and the most popular ones. Different levels will be assigned a different class to be themed in tagadelic.css'),
   );
+  
+  $options = array('3600' => t('1 hour'), '10800' => t('3 hours'), '21600' => t('6 hours'), '43200' => t('12 hours'), '86400' => t('24 hours'));
+  $fom['tagadelic_cache_time']= array(
+    '#type' => 'select',
+    '#title' => t('Cache expire time'),
+    '#default_value' => variable_get('tagadelic_cache_time', 86400),
+    '#description' => t('The time the tag cloud is stored for before being refreshed.'),
+  );
+  
+  
   return system_settings_form($form);
 }
 
@@ -208,13 +218,32 @@ function tagadelic_tags_lists($node) {
  * @return An <em>unordered</em> array with tags-objects, containing the attribute $tag->weight;
  */
 function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) {
-  //CACHING! PLease! Send! in! your! patches! :)
-  if (!is_array($vids) || count($vids) == 0) {
-    return array();
+  // CACHING! PLease! Send! in! your! patches! :)
+  
+  // build the options so we can cache multiple versions
+  $options = implode($vids) .'_'. $steps .'_'. $size;
+  
+  // Check if the cache exists
+  $cache_name = 'tagadelic_cache_'. $options;
+  $cache = cache_get($cache_name);
+  
+  // make sure data is less than 1 day old
+  if( $cache->created > (time() - variable_get('tagadelic_cache_time', 86400))) {
+    $tags = unserialize($cache->data);
   }
-  $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN ('. substr(str_repeat('%d,', count($vids)), 0, -1) .') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $vids, 0, $size);
+  else {
+  
+    if (!is_array($vids) || count($vids) == 0) {
+      return array();
+    }
+    $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN ('. substr(str_repeat('%d,', count($vids)), 0, -1) .') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $vids, 0, $size);
+    
+    $tags = tagadelic_build_weighted_tags($result, $steps);
 
-  return tagadelic_build_weighted_tags($result, $steps);
+    cache_set($cache_name, 'cache', serialize($tags));
+  }
+  
+  return $tags;
 }
 
 /**
