I am trying to implement transient fragments, I've been doing what is suggested here: http://ift.tt/14uGgEO
Here is my code, in functions.php
function fragment_cache($key, $ttl, $function) {
// getting a custom cache optin value, randomly generated in backend when a user hits "flush cache" button
$cache_version = get_option( 'clear_cache' );
if ( is_user_logged_in() ) {
call_user_func($function);
return;
}
$key = apply_filters('fragment_cache_prefix', 'fragment_cache_').$key.$cache_version;
$output = get_transient($key);
if ( empty($output) ) {
ob_start();
call_user_func($function);
$output = ob_get_clean();
set_transient($key, $output, $ttl);
}
echo $output;
}
And here is my code in my page
<?php while ( have_posts() ) : the_post(); ?>
<?php
fragment_cache('post' . $post->ID, DAY_IN_SECONDS, function() {
include( locate_template( 'partials/related_article.php' ) );
});
?>
<?php endwhile; ?>
where in the include I am just posting a title and an image
My issue is that the code doesn't throw errors, but if I change my article title, I see the new title instead of the cached version. Any idea?
Aucun commentaire:
Enregistrer un commentaire