Skip the filter cache altogether

kbahey - July 29, 2007 - 21:54
Project:Memcache API and Integration
Version:5.x-1.3
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

Drupal filter cache hashes most strings and stores the result in the database.

On large sites, I have found that the filter cache consumes more database resources than it it worth.

I have resorted to hacking core to prevent this caching (pre-5.x), or creating a custom includes/cache.inc that does that.

Now with memcached, the amount of memory taken by the filter cache can be troublesome for small memcached configurations (e.g. memcache running on the same box), since it eats up memory and hence eats up the file system buffers and the database cache.

So, here is a patch that modifies memcache.inc to skip the filter cache altogether.

--- memcache.inc        2007-07-29 14:59:39.000000000 -0400
+++ memcache-nofilter.inc       2007-07-29 14:22:43.000000000 -0400
@@ -15,6 +15,9 @@
  *   'cache_menu', 'cache_page', or 'cache' for the default cache.
  */
function cache_get($key, $table = 'cache') {
+  if ($table == 'cache_filter') {
+    return 0;
+  }
   return dmemcache_get($key, $table);
}

@@ -45,6 +48,9 @@ function cache_get($key, $table = 'cache
  */
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
   // Create new cache object.
+  if ($table == 'cache_filter') {
+    return;
+  }
   $cache = new stdClass;
   $cache->cid = $cid;
   $cache->data = is_object($data) ? memcache_clone($data) : $data;
@@ -84,6 +90,9 @@ function cache_clear_all($cid = NULL, $t
   // Memcache logic is simpler because memcache doesn't have a minimum cache
   // lifetime consideration (it handles it internally), and doesn't support
   // wildcards.
+  if ($table == 'cache_filter') {
+    return;
+  }
   $bin = empty($table) ? 'cache' : $table;
   if (empty($cid) || $cid == '*') {
     dmemcache_flush($table);

If you want to make this a configurable option (e.g. disable caching for certain tables), I can add a variable_get() that does that to avoid the end user need to patch, and make it apply to any table (on/off for each table). Just let me know if this has a chance to get in, and I will roll a better patch.

#1

moshe weitzman - July 30, 2007 - 00:33

or just add a filter to your input format which is not cacheable (but otherwise does nothing). that prevents filter cache, without core hack.

#2

robertDouglass - July 30, 2007 - 08:33
Status:active» won't fix

I'd support a general mechanism for not caching certain bins (since the default now is to cache everything that comes into cache_set), but I'm not keen on making this type of decision for all websites in advance.

 
 

Drupal is a registered trademark of Dries Buytaert.