Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.287
diff -u -p -r1.287 filter.module
--- modules/filter/filter.module	30 Aug 2009 06:04:09 -0000	1.287
+++ modules/filter/filter.module	5 Sep 2009 10:29:45 -0000
@@ -172,6 +172,7 @@ function filter_format_save($format) {
   }
   $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_list_cmp($a, $b) {
 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;
 }
 
 /**
