• Resolved dimelevov

    (@dimelevov)


    Hi,

    Is there a way to exclude from page caching for templates like:
    /wp-content/themes/theme_name/views/en/base.twig
    Because we have some variables inside that should be relative, like user country, which is based on user location.

    • This topic was modified 1 year, 1 month ago by dimelevov.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @dimelevov

    Thank you for reaching out and I am happy to help!
    You can always exclude specific page from being cached by adding the URi to Performance>Page Cache>Advanced>Never Cache following pages: field, for example: /some-page/

    You can allso add a constants to specific template:

    define(‘DONOTCACHEPAGE’, true);

    Let me know if this helps!

    Thanks!

    Thread Starter dimelevov

    (@dimelevov)

    Hello @vmarko
    Thank you for your answer.

    But what if I use WP widget with php code where I call php function which retun the user country based on user location and it work good when I use it directly in php file, but here in the widget it is cached.

    If I disable the page cache, it works fine. However, with the page cache active (Disk: Enhanced), I see an incorrect location. This likely occurs with the first user who arrives after the page cache is activated or purged.

    The same is happning and with $_SERVER[“HTTP_CF_IPCOUNTRY”]

    Thanks

    Thread Starter dimelevov

    (@dimelevov)

    Hi,

    I have also added a custom post views counter function that I invoke on single.php, and it works only the first time if the page cache is enabled.

    function set_post_view() {
    $key = 'post_views_count';
    $post_id = get_the_ID();

    $count = (int) get_post_meta($post_id, $key, true);

    $count++;

    update_post_meta($post_id, $key, $count);
    }

    Strange…
    We have very good result with page cache that is reason why I want to have enabled.

    Thanks

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @dimelevov

    Thank you for your feedback.
    In this case, you can use Page Fragment Cache and use the mfunc and mclude comments as a replacement of the PHP tags

    I hope this helps!

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Page cache issue with caching variable’ is closed to new replies.