diff --git a/rules/rules.install b/rules/rules.install
index ee0d830..1185777 100644
--- a/rules/rules.install
+++ b/rules/rules.install
@@ -22,7 +22,6 @@ function rules_install() {
 function rules_uninstall() {
   drupal_load('module', 'rules');
   drupal_uninstall_schema('rules');
-  variable_del('rules_inactive_sets');
   variable_del('rules_show_fixed');
   variable_del('rules_hide_token_message');
   variable_del('rules_debug');
@@ -173,7 +172,14 @@ function rules_update_6005() {
   return $ret;
 }
 
+/**
+ * Remove the rules_inactive_sets variable.
+ */
+function rules_update_6006() {
+  variable_del('rules_inactive_sets');
 
+  return array();
+}
 
 /**
  * Transform a workflow-ng rule into a rule
diff --git a/rules/rules.module b/rules/rules.module
index 927bfcb..114d9ee 100644
--- a/rules/rules.module
+++ b/rules/rules.module
@@ -170,9 +170,9 @@ function rules_get_rule_set($set_name, $reset = FALSE) {
       }
       // Get all inactive sets and store them to speed up later calls.
       $inactive_sets = array_diff(array_keys(rules_get_rule_sets()), array_keys($sets));
-      // If the inactive sets have changed, update the variable.
-      if ($inactive_sets != variable_get('rules_inactive_sets', array())) {
-        variable_set('rules_inactive_sets', $inactive_sets);
+
+      if ($inactive_sets != rules_inactive_sets()) {
+        rules_inactive_sets($inactive_sets);
       }
 
       _rules_get_rule_set_initialize($sets);
@@ -191,6 +191,39 @@ function _rules_get_rule_set_initialize(&$sets) {
 }
 
 /**
+ * Maintains a cache of empty rules sets.
+ *
+ * @param set
+ *   An array of empty rules sets. If passed both the static and persistent
+ *   caches will be updated to the new value.
+ *
+ * @return
+ *   An array of empty rules sets.
+ */
+function rules_inactive_sets($set = array()) {
+  static $inactive_sets;
+  if ($set) {
+    $inactive_sets = $set;
+    cache_set('rules_inactive_sets', $set, 'cache_rules');
+    return $set;
+  }
+  else {
+    if (isset($inactive_sets)) {
+      return $inactive_sets;
+    }
+    else {
+      if ($cached = cache_get('rules_inactive_sets', 'cache_rules')) {
+        $inactive_sets = $cached->data;
+      }
+      else {
+        $inactive_sets = array();
+      }
+      return $inactive_sets;
+    }
+  }
+}
+
+/**
  * Actually retrieves all active rules bypassing the cache
  */
 function _rules_get_rule_sets() {
@@ -222,8 +255,8 @@ function _rules_rule_is_active($rule) {
  */
 function rules_clear_cache($immediate = TRUE) {
   cache_clear_all('*', 'cache_rules', TRUE);
-  variable_del('rules_inactive_sets');
   if ($immediate) {
+    rules_inactive_sets(array());
     rules_get_rule_set(NULL, TRUE);
     rules_gather_data('', 'all', FALSE, TRUE);
     rules_get_configured_items(NULL, TRUE);
@@ -234,7 +267,6 @@ function rules_clear_cache($immediate = TRUE) {
  * Implementation of hook_flush_caches().
  */
 function rules_flush_caches() {
-  variable_del('rules_inactive_sets');
   return array('cache_rules');
 }
 
