Created
October 12, 2012 23:18
-
-
Save tollmanz/3882195 to your computer and use it in GitHub Desktop.
Cache Google Analytics Data with Force Argument
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 | |
function zt_get_top_posts( $force = false ) { | |
// Define our cache key | |
$cache_key = 'zt-top-posts'; | |
// Attempt to grab data from cache | |
$top_posts = wp_cache_get( $cache_key ); | |
// If not found in cache or forced, regenerate | |
if ( false === $top_posts || true === $force ) { | |
// Get posts from GA | |
$top_posts = zt_generate_top_posts(); | |
// If none were found, save a dummy value so the caller knows that | |
if ( false === $top_posts ) | |
$top_posts = 'none-found'; | |
// Set the result to the cache | |
wp_cache_set( $cache_key, $top_posts, 3600 ); | |
} | |
return $top_posts; | |
} | |
function zt_refresh_top_posts() { | |
return zt_get_top_posts( true ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment