Description:
This patch is designed to prevent cache stampedes when updating pages in the Drupal page cache. When serving cached pages, logic checks the timestamp of the cached page -- if older than the global timestamp we try to grab a lock. Only one user can grab the lock for a given page at a time. If the user fails to grab the lock, a stale version of the cached page is returned. Once the page is rebuilt, the new version is returned on subsequent requests.
If using this patch, it is highly recommended that you also apply the page-cache-memcache lock patch. Attempting to use this patch in production without memcache will inevitably result in many stale locks as this patch currently does not provide any garbage collection. This patch is intended to be used together with the external page-cache patch.
Here's an ASCII art explanation of the patch:
Timer Action
0ms:
|----> Page request #1, obtain lock, rebuild page
1ms:
|----> Page request #2, failed to obtain lock, serve page from cache
|
|----> Page request #n, failed to obtain lock, serve page from cache
|
250ms:
| Page request #1 finished building new page cache, page cache updated
|----> Page request #n+1, up-to-date, nothing to rebuild, serve from cache
To use, you will need to create a 'cache_lock' cache table.
For MySQL:
CREATE TABLE cache_lock (
cid varchar(255) NOT NULL default '',
data longblob,
expire int NOT NULL default '0',
created int NOT NULL default '0',
headers text,
serialized int(1) NOT NULL default '0',
PRIMARY KEY (cid),
INDEX expire (expire)
) /*!40100 DEFAULT CHARACTER SET UTF8 */;
For PostgreSQL:
CREATE TABLE cache_lock (
cid varchar(255) NOT NULL default '',
data bytea,
expire int NOT NULL default '0',
created int NOT NULL default '0',
headers text,
serialized smallint NOT NULL default '0',
PRIMARY KEY (cid)
);
Status:
This patch has not been merged into any release of Drupal.
Patch:
http://tag1consulting.com/patches#lock
Original patch source:
http://drupal.org/node/230290
http://drupal.org/files/issues/pagecache_lock3.patch
Referenced external pagecache:
http://tag1consulting.com/patches/external_pagecache
