Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.286
diff -u -r1.286 filter.module
--- modules/filter/filter.module	29 Aug 2009 03:55:44 -0000	1.286
+++ modules/filter/filter.module	29 Aug 2009 06:01:52 -0000
@@ -172,6 +172,7 @@
   }
   $format->roles = $roles;
   $format->name = trim($format->name);
+  $format->cache = filter_cacheable(array_keys(array_filter($format->filters)));
 
   // Add a new text format.
   if (empty($format->format)) {
@@ -459,16 +460,34 @@
 function filter_resolve_format($format) {
   return $format == FILTER_FORMAT_DEFAULT ? variable_get('filter_default_format', 1) : $format;
 }
+
 /**
  * Check if text in a certain text format is allowed to be cached.
  */
 function filter_format_allowcache($format) {
-  static $cache = array();
   $format = filter_resolve_format($format);
-  if (!isset($cache[$format])) {
-    $cache[$format] = db_query('SELECT cache FROM {filter_format} WHERE format = :format', array(':format' => $format))->fetchField();
+  $format = filter_format_load($format);
+  return !empty($format->cache);
+}
+
+/**
+ * Helper function to check if a text format that contains the given filters
+ * can be cached. 
+ *
+ * @param $filters
+ *   An array of filter names. 
+ * @return
+ *   TRUE if all the filters are cacheable, FALSE otherwise.
+ */
+function filter_cacheable(array $filters) {
+  $filter_info = filter_get_filters();
+  foreach ($filters as $name) {
+    // The default is 'cache' => TRUE.
+    if (isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
+      return FALSE; 
+    }
   }
-  return $cache[$format];
+  return TRUE;
 }
 
 /**
