PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / trunk
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript vtrunk
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
← All changes | inc/cache/class-berqcache.php +35 -19 4.0.29trunk View file →
@@ -51,9 +51,9 @@
51 51 add_action('berqwp_flush_page_cache', 'bwp_remove_recently_optimized_entry', 10, 1);
52 52
53 53 add_action('init', [$this, 'bypass_cache']);
54 54
55 - add_action('init', [$this, 'bypass_cache']);
55 + // add_action('init', [$this, 'bypass_cache']);
56 56
57 57 // Flush cache when there's a new comment
58 58 add_action('wp_set_comment_status', [$this, 'handle_new_comment'], 10, 2);
59 59
@@ -92,11 +92,13 @@
92 92 // Apache htaccess cache rules (skip on LiteSpeed — remove any existing rules)
93 93 add_action('berqwp_activate_plugin', 'bwp_write_htaccess_rules');
94 94 add_action('berqwp_flush_all_cache', 'bwp_write_htaccess_rules');
95 95 add_action('berqwp_deactivate_plugin', 'bwp_remove_htaccess_rules');
96 +
96 97 if (bwp_is_openlitespeed_server()) {
97 98 add_action('berqwp_activate_plugin', 'bwp_remove_htaccess_rules');
98 99 }
100 +
99 101 add_action('berqwp_on_update_sandbox_mode', 'bwp_sync_htaccess_on_sandbox_change');
100 102
101 103 // Clear queue list on cloud
102 104 add_action('berqwp_deactivate_plugin', 'berqwp_clear_cache_queue');
@@ -481,12 +483,12 @@
481 483 function brust_cache_for_loggedin()
482 484 {
483 485 if (is_user_logged_in()) {
484 486 // Add Vary: Cookie header to differentiate cached versions for logged-in users
485 - header('Vary: Cookie');
486 - header("Cache-Control: no-cache, no-store, must-revalidate");
487 - header("Pragma: no-cache");
488 - header("Expires: 0");
487 + header('Vary: Accept-Encoding, Cookie');
488 + // header("Cache-Control: no-cache, no-store, must-revalidate");
489 + // header("Pragma: no-cache");
490 + // header("Expires: 0");
489 491 }
490 492 }
491 493
492 494 function handle_post_status_update($new_status, $old_status, $post)
@@ -897,22 +899,27 @@
897 899 // berqHeartbeat::add_queue($page_url);
898 900 warmup_cache_by_url($page_url);
899 901 }
900 902
903 + static function miss_cache_headers() {
904 + header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true);
905 + header('CDN-Cache-Control: no-store', true); // Cloudflare
906 + header('Surrogate-Control: no-store', true); // Varnish
907 + header('X-Accel-Expires: 0', true); // Nginx FastCGI
908 + header("X-BerqWP-Cache: MISS");
909 + }
910 +
901 911 function html_cache()
902 912 {
903 913
904 914 // Bypass cache for Photon
905 915 if (!empty($_COOKIE['berqwpnocache'])) {
906 - header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0', true);
907 - header('CDN-Cache-Control: no-store', true); // Cloudflare
908 - header('Surrogate-Control: no-store', true); // Varnish
909 - header('X-Accel-Expires: 0', true); // Nginx FastCGI
910 -
916 + self::miss_cache_headers();
911 917 return;
912 918 }
913 919
914 920 if (!self::should_cache()) {
921 + self::miss_cache_headers();
915 922 return;
916 923 }
917 924
918 925 $page_url = self::get_page_url();
@@ -917,13 +924,15 @@
917 924
918 925 $page_url = self::get_page_url();
919 926
920 927 if (empty($page_url)) {
928 + self::miss_cache_headers();
921 929 return;
922 930 }
923 931
924 932 // Disable cache for unknown query parameters
925 933 if (strpos($page_url, '?') !== false) {
934 + self::miss_cache_headers();
926 935 return;
927 936 }
928 937
929 938 if (is_singular()) {
@@ -929,8 +938,9 @@
929 938 if (is_singular()) {
930 939 $post_type = get_post_type();
931 940
932 941 if (empty($post_type) || !in_array($post_type, get_option('berqwp_optimize_post_types'))) {
942 + self::miss_cache_headers();
933 943 return;
934 944 }
935 945 } elseif (is_archive()) {
936 946 $queried_object = get_queried_object();
@@ -938,8 +948,9 @@
938 948 if ($queried_object instanceof WP_Term && !empty($queried_object->taxonomy)) {
939 949 $current_taxonomy = $queried_object->taxonomy;
940 950
941 951 if (!in_array($current_taxonomy, get_option('berqwp_optimize_taxonomies'))) {
952 + self::miss_cache_headers();
942 953 return;
943 954 }
944 955 }
945 956 }
@@ -947,8 +958,9 @@
947 958
948 959 $status_code = http_response_code();
949 960
950 961 if ($status_code !== 200) {
962 + self::miss_cache_headers();
951 963 return;
952 964 }
953 965
954 966 $berqconfigs = berqConfigs::getInstance();
@@ -968,16 +980,22 @@
968 980 header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
969 981 header('X-File-Size: ' . filesize($cache_file), true);
970 982 header('Content-Type: text/html; charset=utf-8');
971 983 header("X-served: WP Hook");
972 - header('Vary: Cookie');
984 + header('Vary: Accept-Encoding, Cookie');
985 + header("X-BerqWP-Cache: HIT");
973 986
974 987 if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified) || (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag)) {
975 988 // The client's cache is still valid based on Last-Modified, respond with a 304 Not Modified
976 989 header('HTTP/1.1 304 Not Modified');
977 990 // header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
978 - header("Expires: 0");
979 - header('Cache-Control: no-cache, must-revalidate');
991 + // header("Expires: 0");
992 + // header('Cache-Control: no-cache, must-revalidate');
993 +
994 + header('Cache-Control: public, max-age=600, s-maxage=2592000, stale-while-revalidate=86400', true);
995 + header('cdn-cache-control: max-age=2592000');
996 + header('Cache-Tag: ' . wp_parse_url(home_url())['host']);
997 +
980 998 exit();
981 999 }
982 1000
983 1001 // Prevent PHP/Apache from re-compressing the already-gzipped cache file
@@ -988,11 +1006,12 @@
988 1006 while (ob_get_level()) {
989 1007 ob_end_clean();
990 1008 }
991 1009
992 - header('Cache-Control: public, max-age=0, s-maxage=3600, must-revalidate', true);
1010 + header('Cache-Control: public, max-age=600, s-maxage=2592000, stale-while-revalidate=86400', true);
1011 + header('cdn-cache-control: max-age=2592000');
1012 + header('Cache-Tag: ' . wp_parse_url(home_url())['host']);
993 1013 // header("Content-Security-Policy: script-src 'self' blob: 'unsafe-inline'");
994 - header('Vary: Accept-Encoding, Cookie');
995 1014 header('Content-Encoding: gzip', true);
996 1015 header('Content-Length: ' . filesize($cache_file), true);
997 1016 readfile($cache_file);
998 1017 exit();
@@ -997,12 +1016,9 @@
997 1016 readfile($cache_file);
998 1017 exit();
999 1018 }
1000 1019
1001 - header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
1002 - header('CDN-Cache-Control: no-store'); // Cloudflare
1003 - header('Surrogate-Control: no-store'); // Varnish
1004 - header('X-Accel-Expires: 0'); // Nginx FastCGI
1020 + self::miss_cache_headers();
1005 1021
1006 1022 self::purge_page($page_url);
1007 1023
1008 1024 if (!berqwp_can_use_cloud()) {