This (untested and experimental) code allows to create a primary / secondary engine.

To use, configure it this way:

$conf['cache_router'] = array(
  '<bin>' => array(
    'engine' => 'hiearchical',
    'primary_engine' => array(
       // Your primary (authoritative) engine configuration.
       'engine' => 'db',
       'server' => array(),
       'shared' => TRUE,
    ),
    'secondary_engine' => array(
       // Your secondary (slave) engine configuration.
       'engine' => 'apc',
       'server' => array(),
       'shared' => TRUE,
    ),
    // The maximum inconsistency window.
    'tombstone_delay' => 10,
  ),
);
CommentFileSizeAuthor
hierarchy-router.patch3.3 KBdamien tournoud

Comments

damien tournoud’s picture

Title: Implement a hiarchical (primary / secondary) engine » Implement a hierachical (primary / secondary) engine
david strauss’s picture

Title: Implement a hierachical (primary / secondary) engine » Implement a hierarchical (primary / secondary) engine

The caching hierarchy needs to understand two things:
* Which engines are known to guarantee coherency. All engines do on a single server. APC does not when you have multiple web servers.
* Storage into the cache(s) must have an option to specify whether coherency is required. Coherency should be required by default.

david strauss’s picture

Status: Needs review » Needs work
damien tournoud’s picture

The caching hierarchy needs to understand two things:
* Which engines are known to guarantee coherency. All engines do on a single server. APC does not when you have multiple web servers.
* Storage into the cache(s) must have an option to specify whether coherency is required. Coherency should be required by default.

For D6 and the cache router, it is your responsibility to configure all this correctly, by understanding which "cache bin" requires consistency and which cache engine is able to offer it. The "hiearchy" set up by design never guarantees consistency, but requires that at least the "primary engine" does.

For D7, I suggest we implement a "cache location" parameter. This could be "node local", "cluster wide, short-term" and "cluster wide, long-term". Depending of the cache engines installed, the routing algorithm will choose an engine to satisfy the requirements of the caller. On a stock Drupal install, all those will be stored in db. On a more advanced setup, those could be APC, Memcache and DB respectively.

slantview’s picture

wow, this is like a dream, i've been wanting to work on this for so long.

thank you x 100.

my typical recommendation for people is to use cache router in the following manner

shared hosting:
use file cache and/or apc if available

single server:
use apc cache and/or memcache.

multiple web servers:
use memcache only

although with the heirarchalCache, we could make the following recommendations:

shared hosting:
use file cache and apc if available, secondary cache use db

single server:
use apc and/or memcache, and either db or file as backup

multiple server:
use memcache with either file or db backup