make navigation use cache

This commit is contained in:
John Bintz 2009-11-07 11:52:01 -05:00
parent b3192c3bbb
commit f35adb3f51
2 changed files with 48 additions and 26 deletions

View File

@ -11,6 +11,15 @@ class ComicPressNavigation {
function get_post_nav($post) {
$nav = array();
if (is_object($post)) {
if (isset($post->ID)) {
$cache_key = 'navigation-' . $post->ID;
if (($result = wp_cache_get($cache_key, 'comicpress')) !== false) {
foreach ($result as $key => $post_id) {
$nev[$key] = get_post($post_id);
}
}
// global previous/next
foreach (array('previous', 'next') as $field) {
@ -36,8 +45,17 @@ class ComicPressNavigation {
}
}
$cache_data = array();
foreach ($nav as $key => $output_post) {
if (!empty($output_post)) { $cache_data[$key] = $output_post->ID; }
}
wp_cache_set($cache_key, $cache_data, 'comicpress');
return $nav;
}
}
}
}
?>

View File

@ -40,7 +40,11 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
$this->nav->_dbi = $dbi;
$this->nav->_storyline = $storyline;
$this->assertFalse(wp_cache_get('navigation-1', 'comicpress'));
$this->nav->get_post_nav($post);
$this->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false);
}
}