我如何为特定 php 文件禁用缓存?

How could I disable caching, for specific php files?

我目前正在一个 WordPress 驱动的电子商务网站上工作,我选择的购物平台是 WooCommerce。

有没有一种方法可以不使用插件来阻止浏览器缓存某些 php 文件?在这种情况下,'header.php' 和 'cart.php' 文件?我的假设是,需要对“.htacess”文件进行一些修改,但我可能错了。

不熟悉 woocommerce,但通常您应该能够将以下内容添加到 php 文件中:

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

我发现了问题。我完全 overlooked/forgot,我在 .htaccess 文件中有以下缓存代码。小学生错误!

删除下面的代码后,篮子缓存问题就解决了。

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

如果我发现一种缓存网站的方法,而不缓存篮子,我会把它添加到这个答案中。