HuyPV
Wednesday, October 14, 2009
$post_id = (int) $_GET['post_id'];
$memcached = new Memcache;
$memcached->connect('localhost', 11211);
if (($row = $memcached->get('post_id_' . $post_id)) === false) {
echo 'Init cache
';
$rs = mysql_query('SELECT * FROM post WHERE post_id = ' . $post_id);
if ($rs && mysql_num_rows($rs) > 0) {
$row = mysql_fetch_assoc($rs);
// cache compressed for 1 hour
$memcached->set('post_id_' . $post_id, $row, MEMCACHE_COMPRESSED, time() + 3600);
}
} else {
echo 'Loaded from cache
';
}
var_dump($row);
Title:
Memcache Example
Description:
$post_id = (int) $_GET['post_id']; $memcached = new Memcache; $memcached->connect('localhost', 11211); if (($row = $memca...
...
Rating:
4