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

Yoast / wordpress-seo / 9f70c0278dfa8a47317c8094b5259465fbcd3325

25 Nov 2025 01:51PM UTC coverage: 52.323% (-0.7%) from 52.975%
9f70c0278dfa8a47317c8094b5259465fbcd3325

Pull #22675

github

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

8197 of 15362 branches covered (53.36%)

Branch coverage included in aggregate %.

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

376 existing lines in 10 files now uncovered.

31700 of 60889 relevant lines covered (52.06%)

39221.69 hits per line

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

0.0
/src/schema-aggregator/application/cache/xml-manager.php
1
<?php
2

3
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
5
namespace Yoast\WP\SEO\Schema_Aggregator\Application\Cache;
6

7
use Exception;
8
use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Config;
9

10
/**
11
 * Cache manager for the XML sitemap.
12
 *
13
 * Manages cache storage/retrieval/invalidation using WordPress Transients API.
14
 */
15
class Xml_Manager {
16
        /**
17
         * Cache key prefix
18
         *
19
         * @var string
20
         */
21
        private const CACHE_PREFIX = 'yoast_schema_aggregator';
22

23
        /**
24
         * Cache version for invalidation
25
         *
26
         * @var int
27
         */
28
        private const CACHE_VERSION = 1;
29

30
        /**
31
         * Configuration provider
32
         *
33
         * @var Config
34
         */
35
        private $config;
36

37
        /**
38
         * Constructor
39
         *
40
         * @param Config $config Configuration provider.
41
         */
NEW
42
        public function __construct( Config $config ) {
×
NEW
43
                $this->config = $config;
×
44
        }
45

46
        /**
47
         * Get cached data for a page.
48
         *
49
         * @return string|null Cached data or null.
50
         */
NEW
51
        public function get(): ?string {
×
52
                try {
NEW
53
                        if ( ! $this->config->cache_enabled() ) {
×
NEW
54
                                return null;
×
55
                        }
56

NEW
57
                        $key = $this->get_cache_key();
×
58

NEW
59
                        $data = \get_transient( $key );
×
60

NEW
61
                        if ( $data === false ) {
×
NEW
62
                                return null;
×
63
                        }
NEW
64
                        if ( ! \is_string( $data ) ) {
×
NEW
65
                                \delete_transient( $key );
×
66

NEW
67
                                return null;
×
68
                        }
69

NEW
70
                        return $data;
×
71

NEW
72
                } catch ( Exception $e ) {
×
NEW
73
                        return null;
×
74
                }
75
        }
76

77
        /**
78
         * Set cache data for a page.
79
         *
80
         * @param string $data Data to cache.
81
         *
82
         * @return bool Success.
83
         */
NEW
84
        public function set( string $data ): bool {
×
85
                try {
NEW
86
                        $key        = $this->get_cache_key();
×
NEW
87
                        $expiration = $this->config->get_expiration( [ $data ] );
×
88

NEW
89
                        return \set_transient( $key, $data, $expiration );
×
90

NEW
91
                } catch ( Exception $e ) {
×
NEW
92
                        return false;
×
93
                }
94
        }
95

96
        /**
97
         * Invalidate cache for the xml sitemap.
98
         *
99
         * @return bool Success.
100
         */
NEW
101
        public function invalidate(): bool {
×
NEW
102
                        return \delete_transient( $this->get_cache_key() );
×
103
        }
104

105
        /**
106
         * Generate cache key for page.
107
         *
108
         * @return string Cache key.
109
         */
NEW
110
        private function get_cache_key(): string {
×
NEW
111
                return \sprintf(
×
NEW
112
                        '%s_xml_sitemap_v%d',
×
NEW
113
                        self::CACHE_PREFIX,
×
NEW
114
                        self::CACHE_VERSION
×
NEW
115
                );
×
116
        }
117
}
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