@@ -534,6 +534,16 @@ public function get_page_cache_detail( $use_previous_result = false ) {
534534 ];
535535 }
536536
537+ /**
538+ * Callback for {@see get_page_cache_headers()}.
539+ *
540+ * @param string $header_value Header value.
541+ * @return bool Whether header contains the value "hit"
542+ */
543+ private static function cache_hit_callback ( string $ header_value ): bool {
544+ return false !== stripos ( $ header_value , 'hit ' );
545+ }
546+
537547 /**
538548 * List of header and it's verification callback to verify if page cache is enabled or not.
539549 *
@@ -543,11 +553,6 @@ public function get_page_cache_detail( $use_previous_result = false ) {
543553 * @return array List of client caching headers and their (optional) verification callbacks.
544554 */
545555 protected static function get_page_cache_headers () {
546-
547- $ cache_hit_callback = static function ( $ header_value ) {
548- return false !== strpos ( strtolower ( $ header_value ), 'hit ' );
549- };
550-
551556 return [
552557 'cache-control ' => static function ( $ header_value ) {
553558 return (bool ) preg_match ( '/max-age=[1-9]/ ' , $ header_value );
@@ -560,10 +565,10 @@ protected static function get_page_cache_headers() {
560565 },
561566 'last-modified ' => '' ,
562567 'etag ' => '' ,
563- 'x-cache ' => $ cache_hit_callback ,
564- 'x-proxy-cache ' => $ cache_hit_callback ,
565- 'cf-cache-status ' => $ cache_hit_callback ,
566- 'x-kinsta-cache ' => $ cache_hit_callback ,
568+ 'x-cache ' => [ self ::class, ' cache_hit_callback ' ] ,
569+ 'x-proxy-cache ' => [ self ::class, ' cache_hit_callback ' ] ,
570+ 'cf-cache-status ' => [ self ::class, ' cache_hit_callback ' ] ,
571+ 'x-kinsta-cache ' => [ self ::class, ' cache_hit_callback ' ] ,
567572 'x-cache-enabled ' => static function ( $ header_value ) {
568573 return 'true ' === strtolower ( $ header_value );
569574 },
@@ -573,8 +578,8 @@ protected static function get_page_cache_headers() {
573578 'cf-apo-via ' => static function ( $ header_value ) {
574579 return false !== strpos ( strtolower ( $ header_value ), 'tcache ' );
575580 },
576- 'x-srcache-store-status ' => $ cache_hit_callback ,
577- 'x-srcache-fetch-status ' => $ cache_hit_callback ,
581+ 'x-srcache-store-status ' => [ self ::class, ' cache_hit_callback ' ] ,
582+ 'x-srcache-fetch-status ' => [ self ::class, ' cache_hit_callback ' ] ,
578583 'cf-edge-cache ' => static function ( $ header_value ) {
579584 return false !== strpos ( strtolower ( $ header_value ), 'cache ' );
580585 },
0 commit comments