• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / f8d50e5bfa3024442897862d50cfa2d5d6a2081e

30 Apr 2025 02:12PM UTC coverage: 52.524% (+0.08%) from 52.444%
f8d50e5bfa3024442897862d50cfa2d5d6a2081e

push

github

FAMarfuaty
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into feature/ai-optimize-classic

7892 of 13944 branches covered (56.6%)

Branch coverage included in aggregate %.

98 of 118 new or added lines in 22 files covered. (83.05%)

2 existing lines in 2 files now uncovered.

29150 of 56580 relevant lines covered (51.52%)

42191.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/dashboard/infrastructure/browser-cache/browser-cache-configuration.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
3
namespace Yoast\WP\SEO\Dashboard\Infrastructure\Browser_Cache;
4

5
use Yoast\WP\SEO\Conditionals\Google_Site_Kit_Feature_Conditional;
6
/**
7
 * Responsible for the browser cache configuration.
8
 */
9
class Browser_Cache_Configuration {
10

11
        /**
12
         * The Site Kit conditional.
13
         *
14
         * @var Google_Site_Kit_Feature_Conditional
15
         */
16
        private $google_site_kit_feature_conditional;
17

18
        /**
19
         * The constructor.
20
         *
21
         * @param Google_Site_Kit_Feature_Conditional $google_site_kit_feature_conditional The Site Kit conditional.
22
         */
23
        public function __construct( Google_Site_Kit_Feature_Conditional $google_site_kit_feature_conditional ) {
2✔
24
                $this->google_site_kit_feature_conditional = $google_site_kit_feature_conditional;
2✔
25
        }
26

27
        /**
28
         * Gets the Time To Live for each widget's cache.
29
         *
30
         * @return array<string, array<string, int>> The cache TTL for each widget.
31
         */
32
        private function get_widgets_cache_ttl() {
6✔
33
                return [
6✔
34
                        'topPages' => [
6✔
35
                                'ttl'  => ( 1 * \MINUTE_IN_SECONDS ),
6✔
36
                        ],
6✔
37
                        'topQueries' => [
6✔
38
                                'ttl'  => ( 1 * \HOUR_IN_SECONDS ),
6✔
39
                        ],
6✔
40
                        'searchRankingCompare' => [
6✔
41
                                'ttl'  => ( 1 * \HOUR_IN_SECONDS ),
6✔
42
                        ],
6✔
43
                        'organicSessions' => [
6✔
44
                                'ttl'  => ( 1 * \HOUR_IN_SECONDS ),
6✔
45
                        ],
6✔
46
                ];
6✔
47
        }
48

49
        /**
50
         * Gets the prefix for the client side cache key.
51
         *
52
         * Cache key is scoped to user session and blog_id to isolate the
53
         * cache between users and sites (in multisite).
54
         *
55
         * @return string
56
         */
57
        private function get_storage_prefix() {
6✔
58
                $current_user  = \wp_get_current_user();
6✔
59
                $auth_cookie   = \wp_parse_auth_cookie();
6✔
60
                $blog_id       = \get_current_blog_id();
6✔
61
                $session_token = isset( $auth_cookie['token'] ) ? $auth_cookie['token'] : '';
6✔
62

63
                return \wp_hash( $current_user->user_login . '|' . $session_token . '|' . $blog_id );
6✔
64
        }
65

66
        /**
67
         * Returns the browser cache configuration.
68
         *
69
         * @return array<string, string|array<string, array<string, int>>>
70
         */
71
        public function get_configuration(): array {
6✔
72
                if ( ! $this->google_site_kit_feature_conditional->is_met() ) {
6✔
NEW
73
                        return [];
×
74
                }
75

76
                return [
6✔
77
                        'storagePrefix'   => $this->get_storage_prefix(),
6✔
78
                        'yoastVersion'    => \WPSEO_VERSION,
6✔
79
                        'widgetsCacheTtl' => $this->get_widgets_cache_ttl(),
6✔
80
                ];
6✔
81
        }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc