Skip to content

Instantly share code, notes, and snippets.

@Hube2
Forked from jeffrey-hearn/functions.php
Created July 2, 2014 23:24
Show Gist options
  • Save Hube2/afcf7801cc385aadbc3d to your computer and use it in GitHub Desktop.
Save Hube2/afcf7801cc385aadbc3d to your computer and use it in GitHub Desktop.
<?php
add_filter( 'posts_request', 'pre_db_hit' );
function pre_db_hit( $request )
{
global $diy_cache_current_request;
$diy_cache_current_request = $request;
// use request string to see if expired...
if ( $diy_cache_expired )
return $request; // Let query happen
return null; // null request shuts down execution of the query
}
add_filter( 'posts_results', 'post_db_hit' );
function post_db_hit( $post_objects )
{
global $diy_cache_current_request;
// use request string to see if expired...
if ( $diy_cache_expired )
{
// Store the post objects in the cache
// under a key consisting of a hash of
// the request string...
} else {
// Get the post objects from your DIY
// cache and return them...
return $cached_post_objects;
}
return $post_objects;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment