Feeds: Cache RSS feeds in global transients.

Moves the caching of RSS feeds requested via `fetch_feed()` from single site transients (`get|set|delete_transient()`) to global transients (`get|set|delete_site_transient()`).

On multisite installs of WordPress, this replaces per site caching with the global multisite cache to allow a single cache to be shared between all sites. This reduces the amount of data stored in the database and improves performance of feeds when multiple sites are ingesting the same URL.

Props rollybueno, spacedmonkey, peterwilsoncc.
Fixes #63719.

Built from https://develop.svn.wordpress.org/trunk@60524


git-svn-id: http://core.svn.wordpress.org/trunk@59860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson
2025-07-30 23:03:30 +00:00
parent 7f1d52d7e0
commit 52a06d5ed4
2 changed files with 9 additions and 8 deletions

View File

@@ -12,6 +12,7 @@
*
* @since 2.8.0
* @since 6.7.0 Now properly implements the SimplePie\Cache\Base interface.
* @since 6.9.0 Switched to Multisite's global cache via the `*_site_transient()` functions.
*/
#[AllowDynamicProperties]
class WP_Feed_Cache_Transient implements SimplePie\Cache\Base {
@@ -84,8 +85,8 @@ class WP_Feed_Cache_Transient implements SimplePie\Cache\Base {
$data = $data->data;
}
set_transient( $this->name, $data, $this->lifetime );
set_transient( $this->mod_name, time(), $this->lifetime );
set_site_transient( $this->name, $data, $this->lifetime );
set_site_transient( $this->mod_name, time(), $this->lifetime );
return true;
}
@@ -97,7 +98,7 @@ class WP_Feed_Cache_Transient implements SimplePie\Cache\Base {
* @return array Data for `SimplePie::$data`.
*/
public function load() {
return get_transient( $this->name );
return get_site_transient( $this->name );
}
/**
@@ -108,7 +109,7 @@ class WP_Feed_Cache_Transient implements SimplePie\Cache\Base {
* @return int Timestamp.
*/
public function mtime() {
return get_transient( $this->mod_name );
return get_site_transient( $this->mod_name );
}
/**
@@ -119,7 +120,7 @@ class WP_Feed_Cache_Transient implements SimplePie\Cache\Base {
* @return bool False if value was not set and true if value was set.
*/
public function touch() {
return set_transient( $this->mod_name, time(), $this->lifetime );
return set_site_transient( $this->mod_name, time(), $this->lifetime );
}
/**
@@ -130,8 +131,8 @@ class WP_Feed_Cache_Transient implements SimplePie\Cache\Base {
* @return true Always true.
*/
public function unlink() {
delete_transient( $this->name );
delete_transient( $this->mod_name );
delete_site_transient( $this->name );
delete_site_transient( $this->mod_name );
return true;
}
}

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.9-alpha-60523';
$wp_version = '6.9-alpha-60524';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.