Skip to content

Instantly share code, notes, and snippets.

@ryanza
Created May 1, 2010 12:57
Show Gist options
  • Save ryanza/386309 to your computer and use it in GitHub Desktop.
Save ryanza/386309 to your computer and use it in GitHub Desktop.
<?php
global $memcache_obj;
global $memcache_key;
global $html;
$server = 'localhost';
$port = '11211';
$protocol = ($_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$memcache_key = md5($protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'|'.serialize($_POST).'|'.serialize($_SESSION));
$memcache_obj = memcache_connect($server, (int)$port);
$html = memcache_get($memcache_obj, $memcache_key);
if ($html)
{
echo $html;
exit;
}
ob_start();
?>
<?php
global $memcache_obj;
global $memcache_key;
global $html;
// get the generate HTML, store it in memcache, and output it to the user
$html = ob_get_contents();
memcache_add($memcache_obj, $memcache_key, $html, false, 600);
ob_end_flush();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment