Last active
August 29, 2015 14:02
-
-
Save aidvu/96088fd9a10e3b326f28 to your computer and use it in GitHub Desktop.
Wordpress/Redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"predis/predis": "dev-master" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
Predis\Autoloader::register(); | |
$client = new Predis\Client(); | |
$set = ''; | |
$key = md5($_SERVER['REQUEST_URI']); | |
$compoundKey = $set . $key; | |
if ($data = $client->get($compoundKey)) { | |
echo $data; | |
} else { | |
ob_start(); | |
/** | |
* Front to the WordPress application. This file doesn't do anything, but loads | |
* wp-blog-header.php which does and tells WordPress to load the theme. | |
* | |
* @package WordPress | |
*/ | |
/** | |
* Tells WordPress to load the WordPress theme and output it. | |
* | |
* @var bool | |
*/ | |
define('WP_USE_THEMES', true); | |
/** Loads the WordPress Environment and Template */ | |
require( dirname( __FILE__ ) . '/wp-blog-header.php' ); | |
$data = ob_get_flush(); | |
ob_end_clean(); | |
$client->set($compoundKey, $data); | |
$client->expire($compoundKey, 86400); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install redis-server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment