Hello everybody!
I'm very interested in creating a modular approach for cache management on Drupal.
Currently, the "cache system" is composed by three functions on includes/bootstrap.inc:

* cache_get($key)
* cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL)
* cache_clear_all($cid = NULL, $wildcard = false)

Well, the first problem is that we may need caching right at the bootstrap time, and modules of /modules/ are not available at this time.
So, for me, the possible solutions are:

1) flag the cache manager (something like /modules/cache.module) as a bootstrap module and make it load right on the top of bootstrap
2) not having it as a module, but different .inc files (as it is with the database layer) that you can set up on the settings.php of the site which "cache driver" to use.

I want this because I would like to use memcached as caching system instead of using the database. Other people may like to use filesystem caches. I think that the best solution could be:

1) Having on sites/*/settings.php an entry like $cache_type = < "memcached" | "database" | "filesystem" > , defaulting to "database" (which is the current cache system). Something like:

// filesystem cache
//$cache_type = "filesystem";
//$cache_options['filesystem']['cachedir'] = 'cache';

// memcached cache
$cache_type = "memcached";
$cache_options['memcached']['servers'][0] = '10.0.0.12:11211:true:5:1:15'; // ip:port:persistent:weight:timeout:retry_interval
$cache_options['memcached']['servers'][1] = '10.0.0.13:11211:true:4:1:15'; // ip:port:persistent:weight:timeout:retry_interval

// default database cache
//$cache_type = "database";

2) Having a DRUPAL_BOOTSTRAP_CACHE (before DRUPAL_BOOTSTRAP_PAGE_CACHE) bootstrap stage, where the $cache_type would be loaded (basically just having its own implementation of the three functions above):

    // somewhere in includes/cache.inc

    $handler = "./includes/cache.$cache_type.inc";
    if (is_file($handler)) {
      include_once $handler;
      if (function_exists('cache_initialize')) {
         cache_initialize($cache_options[$cache_type]);
      }
    } else {
       // show a error message asking $cache_type to be fixed or commented
    }

And that's it. We should be able to use a "modular" cache system without problems (AFAIK).
I want to go ahead and develop this, but I'm skeptical about:
1) changing the core, since I will have to manually upgrade my code everytime a new drupal release is on the wild
2) there may be already something like that planned, and I'll waste my time

What you guys think about that?

Thanks
Daniel

Comments

moshe weitzman’s picture

such a cache system was just committed to HEAD this week. Take a look at the new bootstrap. You will be pleased ... I hope the memcached api and friends will arise soon.

dvsouza’s picture

to know... I'll take a look into that. Probably will do the memcached api myself =P
thanks for the info

--
"Slackware users: Klingons of the computing world."
http://blogs.nshp.org/dsouza

sammy2drupal’s picture

Where is it implemented ?

Can you please guide me as as to how to enable it and disable the default database based caching.