Title: Page cache issue with caching variable
Last modified: February 19, 2025

---

# Page cache issue with caching variable

 *  Resolved [dimelevov](https://wordpress.org/support/users/dimelevov/)
 * (@dimelevov)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/page-cache-issue-with-caching-variable/)
 * Hi,
 * Is there a way to exclude from page caching for templates like:
   /wp-content/themes/
   theme_name/views/en/base.twigBecause we have some variables inside that should
   be relative, like user country, which is based on user location.
    -  This topic was modified 1 year, 3 months ago by [dimelevov](https://wordpress.org/support/users/dimelevov/).

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

 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/page-cache-issue-with-caching-variable/#post-18316523)
 * Hello [@dimelevov](https://wordpress.org/support/users/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](https://wordpress.org/support/users/dimelevov/)
 * (@dimelevov)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/page-cache-issue-with-caching-variable/#post-18318975)
 * Hello [@vmarko](https://wordpress.org/support/users/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](https://wordpress.org/support/users/dimelevov/)
 * (@dimelevov)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/page-cache-issue-with-caching-variable/#post-18319297)
 * 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.
 *     ```wp-block-code
       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](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/page-cache-issue-with-caching-variable/#post-18321171)
 * Hello [@dimelevov](https://wordpress.org/support/users/dimelevov/) 
   Thank you
   for your feedback.In this case, you can use [Page Fragment Cache](https://github.com/BoldGrid/w3-total-cache/wiki/FAQ:-Developers#what-is-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.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

## Tags

 * [page-cache](https://wordpress.org/support/topic-tag/page-cache/)

 * 4 replies
 * 2 participants
 * Last reply from: [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/page-cache-issue-with-caching-variable/#post-18321171)
 * Status: resolved