0
0
Wordpressframework~10 mins

Caching strategies in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable page caching in WordPress using a plugin.

Wordpress
<?php
// Activate caching plugin
add_action('init', function() {
    if (!function_exists('[1]')) {
        return;
    }
    [1]();
});
Drag options to blanks, or click blank then click option'
Awp_cache_init
Bstart_cache
Ccache_start
Denable_cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function name.
Confusing caching initialization with cache clearing.
2fill in blank
medium

Complete the code to clear the cache when a post is updated.

Wordpress
<?php
add_action('save_post', function($post_id) {
    if (wp_is_post_revision($post_id)) {
        return;
    }
    [1]();
});
Drag options to blanks, or click blank then click option'
Aclear_cache
Bwp_cache_clear_cache
Cwp_cache_flush
Dflush_cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function that does not exist in WordPress.
Trying to clear cache with a function meant for starting cache.
3fill in blank
hard

Fix the error in the code to set cache expiration time correctly.

Wordpress
<?php
function set_cache_expiration() {
    $expiration = [1] * 60; // minutes to seconds
    wp_cache_set('cache_expiration', $expiration);
}
Drag options to blanks, or click blank then click option'
A600
B'10'
C10 * 60
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number.
Multiplying by 60 twice.
4fill in blank
hard

Fill both blanks to create a transient cache with expiration.

Wordpress
<?php
set_transient('[1]', $data, [2]);
Drag options to blanks, or click blank then click option'
A'my_cache_key'
B3600
C60
D'cache_data'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable instead of a string for the key.
Setting expiration time too low or as a string.
5fill in blank
hard

Fill all three blanks to retrieve cached data safely.

Wordpress
<?php
$cache = get_transient([1]);
if ([2] === false) {
    $cache = fetch_data();
    set_transient([3], $cache, 3600);
}
Drag options to blanks, or click blank then click option'
A'my_cache_key'
B$cache
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for get and set.
Checking the wrong variable for cache miss.