Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.300
diff -u -p -r1.300 filter.module
--- modules/filter/filter.module	23 Oct 2009 22:24:14 -0000	1.300
+++ modules/filter/filter.module	27 Oct 2009 18:28:48 -0000
@@ -182,6 +182,7 @@ function filter_format_load($format_id) 
  */
 function filter_format_save(&$format) {
   $format->name = trim($format->name);
+  $format->cache = _filter_format_allowcache($format);
 
   // Add a new text format.
   if (empty($format->format)) {
@@ -494,16 +495,48 @@ function _filter_list_cmp($a, $b) {
 
 /**
  * Check if text in a certain text format is allowed to be cached.
+ *
+ * This function can be used to check whether the result of the filtering
+ * process can be cached. A text format may allow caching depending on the
+ * filters enabled.
+ *
+ * @param $format_id
+ *   The text format ID to check.
+ * @return
+ *   TRUE if the given text format allows caching, FALSE otherwise.
  */
 function filter_format_allowcache($format_id) {
-  static $cache = array();
-  if (!isset($cache[$format_id])) {
-    $cache[$format_id] = db_query('SELECT cache FROM {filter_format} WHERE format = :format', array(':format' => $format_id))->fetchField();
-  }
-  return $cache[$format_id];
+  $format = filter_format_load($format_id);
+  return !empty($format->cache);
 }
 
 /**
+ * Helper function to determine whether a given text format can be cached.
+ *
+ * A given text format is allowed to be cached when all the enabled filters in
+ * the text format allow caching.
+ *
+ * @param $format
+ *   The text format object to check.
+ * @return
+ *   TRUE if all the filters enabled in the given text format allow caching,
+ *   FALSE otherwise.
+ *
+ * @see filter_format_allowcache()
+ * @see filter_format_save()
+ */
+function _filter_format_allowcache($format) {
+  $filter_info = filter_get_filters();
+  foreach ($format->filters as $name => $filter) {
+    // By default, 'cache' is TRUE for all filters unless specified otherwise.
+    if (isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
+ 
+/**
  * Retrieve a list of filters for a given text format.
  *
  * @param $format_id
