The Transient API saves data inside the database, which isn’t as effective as APC, but a similar workflow as used for transients can be used for APC. It is important to check if APC is available and active, so its functions are usable. Because this isn’t always the case, it is to consider to add a alternative to APC via Transient API and combine those two caching options in one workflow. Which would assure that there is a caching mechanism available, even if APC isn’t available – this is good practice if your planing to distribute your code and want to make sure that caching works on different environments. If it is only for your own requirements and you have control over the setup, with APC on your server availabel and activated, then you can use only the APC variant, because you know it will work and it is much faster.
Below code shows the exemplary usage of APC:
Set Caching
WP Transient API:
set_transient( $transientname,$go,3600 );
with APC:
apc_add( $transientname,$go,3600 );
Also for deleting
WP Transient API:
delete_transient( $transientname );
with APC:
apc_delete( $transientname );
Caching Queries
$cachequery = 'blog_id_' . $blog->ID;
$cacheexpire = 1800;
if ( $mypost = apc_fetch( $cachequery ) ) {
echo "<!-- cached query -->";
} else {
$mypost = query_posts( $args );
apc_store( $cachequery, $mypost, $cacheexpire );
echo "<!-- caching this -->";
}
APC Documentation
See the documentation of APC for more information and functions.