Our site with Drupal 6.26 (published 2012-05-02) kept crashing because it filled its `cache_menu`
table too quickly.
This is a drop-in replacement for includes/cache.inc
that makes Drupal use a filesystem-based cache instead of the database.
Installation
- Download the file (http://trac.rezo.net/trac/rezo/brow...)
- Rename the old
includes/cache.inc
toincludes/cache.classic.inc
, in case you want to go back. - Install this file as
includes/cache.inc
. - By default, we use the
sys_get_temp_dir()
command to learn where to store the cache files. If you prefer to see what happens, create atmp/
directory (with proper write permissions forwww-data
and a security.htaccess
file); the code will use this directory if it exists.
Compatibility
This has not been tested yet on any other version than Drupal 6.26. If it works for you, please comment in the forum below.
How it works
When Drupal tries to cache some data it uses
cache_set($cid, $data, $table, $expire, $headers)
… our code computes a 4-hexdigits hash key from (cid, table)
, and stores the values (data, headers)
in the file named tmp/a0/3c.cache
.
When Drupal requests this value from the cache, we load the values from the same file, check that the cid
and table
match the request, that the cache has not expire
d, and then return the value.
There will be collisions in this small space (16^4= 65,536
files “only”). But that’s a deliberate feature, because it allows us to avoid using a costly garbage collector [1].
P.S. Something better probably exists somewhere. I just couldn’t find it; if this is useful for you, or if you have suggestions, please comment below.