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

Yoast / wordpress-seo / 3cd34bb9c7b9cedb819c214ddaae5cb49310ce7e

25 Nov 2025 02:37PM UTC coverage: 48.338%. First build
3cd34bb9c7b9cedb819c214ddaae5cb49310ce7e

Pull #22675

github

web-flow
Merge e1e0782a6 into 130f1448f
Pull Request #22675: 804 add caching

0 of 187 new or added lines in 7 files covered. (0.0%)

17512 of 36228 relevant lines covered (48.34%)

3.81 hits per line

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

0.0
/src/schema-aggregator/infrastructure/config.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
namespace Yoast\WP\SEO\Schema_Aggregator\Infrastructure;
4

5
use Exception;
6

7
/**
8
 * Configuration for the Schema Aggregator.
9
 */
10
class Config {
11

12
        /**
13
         * Default items per page
14
         *
15
         * @var int
16
         */
17
        private const DEFAULT_PER_PAGE = 100;
18

19
        /**
20
         * Maximum items per page
21
         *
22
         * @var int
23
         */
24
        private const MAX_PER_PAGE = 100;
25
        /**
26
         * Default cache TTL in seconds
27
         *
28
         * @var int
29
         */
30
        private const DEFAULT_CACHE_TTL = ( 60 * 60 );
31

32
        /**
33
         * Get default items per page
34
         *
35
         * @return int
36
         */
37
        public function get_per_page(): int {
×
38
                $per_page = (int) \apply_filters( 'wpseo_schema_aggregator_per_page', self::DEFAULT_PER_PAGE );
×
39

40
                if ( $per_page > self::MAX_PER_PAGE ) {
×
41
                        $per_page = self::MAX_PER_PAGE;
×
42
                }
43

44
                return $per_page;
×
45
        }
46

47
        /**
48
         * Get maximum items per page
49
         *
50
         * @return int
51
         */
52
        public function get_max_per_page(): int {
×
53
                return self::MAX_PER_PAGE;
×
54
        }
55

56
        /**
57
         * Get expiration time based on data size.
58
         *
59
         * @param array<string> $data Data to cache.
60
         *
61
         * @return int Expiration in seconds.
62
         */
NEW
63
        public function get_expiration( array $data ): int {
×
NEW
64
                $cache_ttl = self::DEFAULT_CACHE_TTL;
×
65
                try {
NEW
66
                        $serialized = \serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Needed for size calculation.
×
67

NEW
68
                        if ( $serialized === false ) {
×
NEW
69
                                return self::DEFAULT_CACHE_TTL;
×
70
                        }
71

NEW
72
                        $size = \strlen( $serialized );
×
73

74
                        // Large payloads: cache longer.
NEW
75
                        if ( $size > 1048576 ) {
×
NEW
76
                                $cache_ttl = ( 6 * \HOUR_IN_SECONDS );
×
77
                        }
78

79
                        // Small payloads: cache shorter.
NEW
80
                        if ( $size < 102400 ) {
×
NEW
81
                                $cache_ttl = ( 30 * \MINUTE_IN_SECONDS );
×
82
                        }
83

NEW
84
                        $cache_ttl = \apply_filters( 'yoast_schema_aggregator_cache_ttl', $cache_ttl );
×
85

NEW
86
                        if ( ! \is_int( $cache_ttl ) || $cache_ttl <= 0 ) {
×
NEW
87
                                return self::DEFAULT_CACHE_TTL;
×
88
                        }
89

NEW
90
                        return $cache_ttl;
×
91

NEW
92
                } catch ( Exception $e ) {
×
NEW
93
                        return self::DEFAULT_CACHE_TTL;
×
94
                }
95
        }
96

97
        /**
98
         * Check if caching is enabled.
99
         *
100
         * @return bool True if caching is enabled, false otherwise.
101
         */
NEW
102
        public function cache_enabled(): bool {
×
NEW
103
                $enabled = \apply_filters( 'yoast_schema_aggregator_cache_enabled', true );
×
104

NEW
105
                if ( \is_bool( $enabled ) ) {
×
NEW
106
                        return $enabled;
×
107
                }
108
                else {
NEW
109
                        return true;
×
110
                }
111
        }
112
}
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