<?php
define(TMPDIR, '/tmp');
function load_abc_data()
{
if (xcache_isset("abc_data")) {
return xcache_get("abc_data");
}
// it worth a lock here to avoid useless yet harmful concurrent
// load from any slow backend (backend=mysql here).
$fp = fopen(TMPDIR . "/abc_data.lock", "w");
flock($fp, LOCK_EX);
// check AGAIN after we get the lock
if (xcache_isset("abc_data")) {
fclose($fp);
return xcache_get("abc_data");
}
mysql_query .... and get $data
xcache_set("abc_data", $data, 120); // save for 2 minutes
fclose($fp);
return $data;
}
?>
http://xcache.lighttpd.net/
http://zhidao.baidu.com/link?url=1WD1lI8Ccm8Cc1uiKhIyyCM4Qf0O3scWUvMZjvgzFkUB9ammuTZoEKR140SEh5BWid6xxtdqpbGgDUCFY5FfOq#