File-based caching no-cache request headers bug

[ad_1]

Hi

I think I’ve found a bug. In sg-cachepress/core/helper/File_Cacher_Trait.php it has a section to “return boolean True if nocache headers exist, false otherwise.”

As part of the has_nocache_headers() function in this section, on line 225 it has this line of code:

foreach ( apache_request_headers() as $header => $value ) {

I believe this should be apache_response_headers() instead of apache_request_headers() as with the way it currently is if you set the ‘cache-control: no-cache’ header using php in WordPress it will still be cached by the file-based caching.

If it is updated to use apache_response_headers() instead then the file-based caching doesn’t cache pages that have a ‘cache-control: no-cache’ header set via php which seems like it would be the desired behaviour.

The way it currently is also has another quirk where if you have ‘disable cache’ ticked in the network tab in dev tools the browser sends the ‘cache-control: no-cache’ header as part of the get request which bypasses the file-based caching as it is set to bypass the cache based on the request header rather than the response header.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer