captcha_points_cache.patch 1.6 KB
diff --git a/captcha.inc b/captcha.inc
index 4dc6f82..eb8b584 100644
--- a/captcha.inc
+++ b/captcha.inc
@@ -64,6 +64,7 @@ function captcha_set_form_id_setting($form_id, $captcha_type) {
       'warning'
     );
   }
+  cache_clear_all('captcha_points:' . $form_id,'cache_captcha');
 }
 
 /**
@@ -82,18 +83,21 @@ function captcha_set_form_id_setting($form_id, $captcha_type) {
  *   or in the form 'captcha/Math'.
  */
 function captcha_get_form_id_setting($form_id, $symbolic = FALSE) {
-  // Fetch setting from database.
-  if (module_exists('ctools')) {
-    ctools_include('export');
-    $object = ctools_export_load_object('captcha_points', 'names', array($form_id));
-    $captcha_point = array_pop($object);
-  }
-  else {
-    $result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id",
-      array(':form_id' =>  $form_id));
-    $captcha_point = $result->fetchObject();
-  }
+  
+  $cache_key = 'captcha_points:' . $form_id;
 
+  $cache = cache_get($cache_key,'cache_captcha');
+  $captcha_point = false;
+  if($cache && !empty($cache->data)){
+    $captcha_point = $cache->data;
+  }else{
+    $captcha_points = captcha_get_captcha_points();
+    if(isset($captcha_points[$form_id])){
+      $captcha_point = $captcha_points[$form_id];
+      cache_set($cache_key,$captcha_point,'cache_captcha',CACHE_PERMANENT);
+    }
+  }
+  
   // If no setting is available in database for the given form,
   // but 'captcha_default_challenge_on_nonlisted_forms' is enabled, pick the default type anyway.
   if (!$captcha_point && variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE)) {