PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / dashboard / infrastructure / browser-cache / browser-cache-configuration.php

browser-cache-configuration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at src/dashboard/infrastructure/browser-cache/browser-cache-configuration.php

63 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 namespace Yoast\WP\SEO\Dashboard\Infrastructure\Browser_Cache;
5
6 /**
7 * Responsible for the browser cache configuration.
8 */
9 class Browser_Cache_Configuration {
10
11 /**
12 * Gets the Time To Live for each widget's cache.
13 *
14 * @return array<string, array<string, int>> The cache TTL for each widget.
15 */
16 private function get_widgets_cache_ttl() {
17 return [
18 'topPages' => [
19 'ttl' => ( 1 * \MINUTE_IN_SECONDS ),
20 ],
21 'topQueries' => [
22 'ttl' => ( 1 * \HOUR_IN_SECONDS ),
23 ],
24 'searchRankingCompare' => [
25 'ttl' => ( 1 * \HOUR_IN_SECONDS ),
26 ],
27 'organicSessions' => [
28 'ttl' => ( 1 * \HOUR_IN_SECONDS ),
29 ],
30 ];
31 }
32
33 /**
34 * Gets the prefix for the client side cache key.
35 *
36 * Cache key is scoped to user session and blog_id to isolate the
37 * cache between users and sites (in multisite).
38 *
39 * @return string
40 */
41 private function get_storage_prefix() {
42 $current_user = \wp_get_current_user();
43 $auth_cookie = \wp_parse_auth_cookie();
44 $blog_id = \get_current_blog_id();
45 $session_token = ( $auth_cookie['token'] ?? '' );
46
47 return \wp_hash( $current_user->user_login . '|' . $session_token . '|' . $blog_id );
48 }
49
50 /**
51 * Returns the browser cache configuration.
52 *
53 * @return array<string, string|array<string, array<string, int>>>
54 */
55 public function get_configuration(): array {
56 return [
57 'storagePrefix' => $this->get_storage_prefix(),
58 'yoastVersion' => \WPSEO_VERSION,
59 'widgetsCacheTtl' => $this->get_widgets_cache_ttl(),
60 ];
61 }
62 }
63