How to fix caching issue in PHP data from database

Im trying to use the code belong for my plugin development but there is a caching issue (I think). Please below for the details.


I created filter to accept the customized url, and I’m querying the database but it seams like the result value is not changing in the browser but changing in the database. So basically the data passed is not returning the updated value from the database.


add_action( 'init',  function() {     add_rewrite_rule('coupon/([a-zA-Z0-9]+)[/]?$  ', 'index.php?coupon=$  matches[1]', 'top'); });  add_filter('query_vars', function( $  query_vars ) {     $  query_vars[] = 'coupon';     return $  query_vars; });  add_action( 'template_include', function( $  template ) {     if ( get_query_var( 'coupon' ) == false || get_query_var( 'coupon' ) == '' ) {         return $  template;     }      ob_clean();     ob_start();      // Check if coupon exists     global $  wpdb;     $  coupon = get_query_var('coupon');      $  coupon_query = $  wpdb->prepare('SELECT * FROM wp_urls WHERE coupon = %s AND claimed_at IS NULL', $  coupon);     $  coupon_available = $  wpdb->query($  coupon_query) ? true : false;      if(!$  coupon_available) {         header('Location: /'); // Redirect to landing page         exit();     }          return plugin_dir_path(__FILE__) . 'views/client/index.php';; } ); 

index.php (Update function with the form)

After clicking submit button, the code below will run.

$  update_query = "UPDATE wp_urls SET                          `email` = %s,                          `phone_number` = %s,                          `first_name` = %s,                          `last_name` = %s,                          `message` = %s,                          `claimed_at` = %s                          WHERE `coupon` = %s";  //  Execute query $  wpdb->query($  wpdb->prepare($  update_query, $  placeholder_values)); 

Expected Result

The expected result should redirect the user to the header('Location: /'); if the coupon is not available.

Any idea?

How to manage page caching to serve different AdSense units for Mobile and Desktop

I’m trying to cache the pages of my website, which are responsive and show the same contents for Desktop and for Mobile, with the exception of the location of the AdSense units if the visit is from Desktop or from Mobile:

  • for Desktop, I place the first ad (a 728×90 banner) just under the page title
  • for Mobile, the first ad is a below-the-fold 300×250 unit

The rest of the HTML contents are identical, except the AdSense code for the first ad. So I cannot cache the pages and I must query the database with the consequent load increment.

I wondered if any of you had similar experiences. Would you place the same AdSense code (e.g. responsive units) for the first ad (for both Desktop and Mobile), just in the below-the-fold of the mobile pages?

CDN & Caching Blocking Email Automation

I’m using Groundhogg with WordPress. I have caching through Litespeed’s plugin, Cloudflare (DNS records are only in my CPanel), and the server itself. All three, together and individually, block emails being sent using Groundhogg. Groundhogg is an email marketing and automation tool. Users cannot get through the basic opt-in funnel. They’ll submit the form and get the confirmation email. When they click the confirm link, they’re oddly taken to a “manage your preferences” page instead of a…

CDN & Caching Blocking Email Automation

Google is caching my homepage almost properly but not other pages

My website is built on NodeJS with ReactJS as frontend and has server side rendering.

Problem 1: Home page is cached properly by Google but other pages are cached without their CSS.

Problem 2: Blogs which are brought dynamically are not shown in the cache.

Link :

Thanks in advance


Error caching static js files in my htaccess file. What does this error mean? [duplicate]

I have this in my .htaccess file:

<IfModule mod_expires.c>   ExpiresActive on  # Perhaps better to whitelist expires rules? Perhaps.   ExpiresDefault                          "access plus 1 month"  # cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)   ExpiresByType text/cache-manifest       "access plus 0 seconds"  # Your document html   ExpiresByType text/html                 "access plus 0 seconds"  # Data   ExpiresByType text/xml                  "access plus 0 seconds"   ExpiresByType application/xml           "access plus 0 seconds"   ExpiresByType application/json          "access plus 0 seconds"  # RSS feed   ExpiresByType application/rss+xml       "access plus 1 hour"  # Favicon (cannot be renamed)   ExpiresByType image/x-icon              "access plus 1 week"  # Media: images, video, audio   ExpiresByType image/gif                 "access plus 1 month"   ExpiresByType image/png                 "access plus 1 month"   ExpiresByType image/jpg                 "access plus 1 month"   ExpiresByType image/jpeg                "access plus 1 month"   ExpiresByType video/ogg                 "access plus 1 month"   ExpiresByType audio/ogg                 "access plus 1 month"   ExpiresByType video/mp4                 "access plus 1 month"   ExpiresByType video/webm                "access plus 1 month"  # HTC files  (css3pie)   ExpiresByType text/x-component          "access plus 1 month"  # Webfonts   ExpiresByType font/truetype             "access plus 1 month"   ExpiresByType font/opentype             "access plus 1 month"   ExpiresByType application/x-font-woff   "access plus 1 month"   ExpiresByType image/svg+xml             "access plus 1 month"   ExpiresByType application/ "access plus 1 month"  # CSS and JavaScript   ExpiresByType text/css                  "access plus 1 year"   ExpiresByType application/javascript    "access plus 1 year"   ExpiresByType text/javascript           "access plus 1 year"    <IfModule mod_headers.c>     Header append Cache-Control "public"   </IfModule>  </IfModule> 

When I do a speed test, I get a C in “cache static content”, because of this:

Leverage browser caching of static assets: 79/100 Learn More

FAILED – (No max-age or expires) –

FAILED – (5.0 minutes) –

FAILED – (15.0 minutes) –

WARNING – (1.8 hours) –

WARNING – (24.0 hours) –|Open+Sans:300,400|Merriweather:400,700

WARNING – (2.0 days) –

WARNING – (2.0 days) –

WARNING – (2.5 days) –

WARNING – (2.5 days) –

WARNING – (2.5 days) –

WARNING – (2.5 days) –

WARNING – (2.5 days) –

WARNING – (2.5 days) –

WARNING – (2.5 days) –

WARNING – (6.9 days) –

WARNING – (6.9 days) –

Why I’m getting these errors? I thought that I’ve already cached js files…

Calculating effective access time in memory caching context

I have went through various problems involving time required to access required data in the context of caching.

They use different formulae in different problems. For example, this answer suggests these formulae:

effective-access-time = hit-rate * cache-access-time                   + miss-rate * lower-level-access-time    effective-access-time = cache-access-time + miss-rate * miss-penalty 

Let me rewrite them:

  1. $ T_{eff}=H_{L1}\times T_{L1} + (1-H_{L1})\times T_{LowerLevelMemories}$
  2. $ T_{eff}=T_{L1}+(1-H_{L1})\times T_{L1MissPenalty}$

$ H_{L1}$ is L1 cache hit rate
$ T_L1$ is L1 cache access time
$ T_{LowerLevelMemories}$ is time to access lower level memories
$ T_{L1MissPenalty}$ is L1 cache miss penalty

About when to use which formula, the answer says:

  • use first formula when lower level memory access time is given and
  • 2nd formula when miss penalty is given.

Is it so?

Let me put $ T_{LowerLevelMemories}=T_M$ , a main memory access time in formula 1. Also, I feel formula 1 ignores that we do indeed access L1 cache when cache miss occurs. So we should also multiply $ (1-H_{L1})$ by $ T_{L1}$ . So formula 1 becomes:

$ T_{eff}=H_{L1}\times T_{L1} + (1-H_{L1})\times (T_M+T_{L1})$ $ =H_{L1}\times T_{L1} + T_M+T_{L1} -H_{L1}\times T_M-H_{L1}\times T_{L1}$
$ =T_{L1}+(1-H_{L1})\times T_M$

This last equation resembles formula 2 above. Also we can interpret that $ T_M$ is exactly the L1 miss penalty. So I feel, we should

  • use formula 2 when we assume L1 is accessed even during miss and
  • formula 1 when we assume L1 is not accessed during miss

However this does not align with what answer has to suggest as quoted above. Am I correct with how to make decision when to use which formula or the quoted suggestion from the answer is correct?

Your Opinions on Caching

My webpages are pretty lean and are scoring 100 in Google's PageSpeed test. They load in less than one second.

Your opinions & advice? — Should I do some caching in my .htaccess to speed them up even more? Or should I just leave good results alone and not tamper with them? (I'm not high-tech and might do something harmful) Sample page:

Magento 2.3.1 varnish and cloudlfare – pages not caching as expected

We have a Magento 2.3.1 store that uses CloudFlare and has Varnish enabled. If we use wget or curl to load a page, that page is cached in Varnish if we try wget or curl again on that same page.

However, if we then test that URL via a browser, the page is not cached. It is then cached after the first browser visit, and then remains cached on reloads from a browser.

We added the CF+Varnish rules as listed at:

but that did not seem to make a difference. We’re using the recommended Magento default.vcl file that is generated.

Any ideas what could be stopping a wget/curl from loading a page into the Varnish cache such that any request from a browser would be served that cached page instead of causing Varnish to cache the page again?