Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #167977 Reply
    Cinzia
    Guest

    Hello,

    I am using the built-in Fragment Cache extension in W3 Total Cache to cache specific parts of my templates. However, I am encountering an issue where the fragment TTL is ignored when Page Caching is active.

    My Setup:
    I have implemented a helper function and registered a fragment group with a 60-second TTL as follows:

    PHP

    // 1. Fragment cache helper function
    function fragment_cache($key, $function) {
    $group = ‘capelli24’;
    $key = apply_filters(‘fragment_cache_prefix’, ‘fragment_cache_’) . $key;
    if (function_exists(‘w3tc_fragmentcache_start’)) {
    if (!w3tc_fragmentcache_start($key, $group)) {
    call_user_func($function);
    w3tc_fragmentcache_end($key, $group);
    }
    } else {
    call_user_func($function);
    }
    }

    // 2. Register fragment cache group with 60s TTL
    add_action(‘w3tc_register_fragment_groups’, function() {
    if (function_exists(‘w3tc_register_fragment_group’)) {
    w3tc_register_fragment_group(‘capelli24’, [], 60);
    }
    });

    // 3. Implementation in template
    fragment_cache(‘band’, function() {
    echo date(‘H:i:s’);
    });

    The Issue:
    In WordPress Admin (Page Cache disabled): The code works perfectly. The time updates every 60 seconds as expected.

    On the Front-end (Page Cache enabled): The fragment does not refresh. I see the same timestamp generated when the Page Cache entry was first created. It appears the full page cache is served before the fragment logic can execute, making the 60s TTL ineffective.

    I am currently testing in a local environment with define(‘W3TC_PRO_DEV_MODE’, true);.

    My Questions:
    – Is Fragment Caching intended to work in conjunction with Page Caching (Disk/Memcached/Redis), or must pages containing fragments be excluded from the Page Cache entirely?

    – Is there a specific configuration or a “Late Initialization” setting required to ensure that fragments are processed dynamically even when the rest of the page is served from cache?

    – If this requires a specific Page Cache Method (e.g., Basic vs. Enhanced), could you please clarify?

    I would appreciate your guidance on the recommended configuration to make this fragment respect its TTL while keeping Page Caching active.

    Thank you.

    #169180 Reply

    Hello Cinzia,

    Thank you for reaching out, and I am happy to help!
    Just to confirm, you have enabled the fragment Cache Extension in the Performance>Extensions settings in the W3 Total Cache?

    What is the Caching method used for fragment caching and also for Page Caching in this case?
    And can you please clarify if you are trying to utilize Fragment Caching as an extension or the page Fragment Caching to exclude specific parts of the page using mfunc?
    Thank you!

    #169217 Reply
    Cinzia
    Guest

    Hi Marko,
    thank you for your response.

    Here are the details you requested:
    – Extension Status: Yes, the Fragment Cache Extension is enabled under Performance > Extensions.
    – Caching Methods:
    – Page Cache: Redis
    – Fragment Cache: Disk

    Implementation method: I am utilizing the Fragment Caching extension API (specifically w3tc_fragmentcache_start and w3tc_fragmentcache_end), not the legacy mfunc tags.

    My main concern: the fragment works correctly when Page Cache is disabled. However, when Page Cache is enabled, the entire page is served as a static file, and the PHP logic for the fragment is never executed, effectively bypassing the 60s TTL I defined.

    Thank you.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Reply #169217 in Fragment Cache TTL not respected when Page Cache is enabled
Your information: