admin管理员组文章数量:1134246
I'm trying to bypass the cache used by fetch_feed, for specific users to force an update, by looking for the transient and deleting it before calling fetch_feed.
if ( $this->bypass ) {
$identifier = md5($this->feedUrl);
$cacheKey = 'feed_' . $identifier;
$cachedResult = get_transient($cacheKey);
delete_transient($cacheKey);
}
$feedData = fetch_feed($this->feedUrl);
This however doesn't generate the correct transient key. They key in the database will be feed_2e798d9381cdbac2bb90151bf553c129 but this code is giving me feed_3f88b9c0e4a4ed755f0216b12b320fa5.
Is there a way to get the correct key from the url, or is there a method to delete the transient key via url?
I'm trying to bypass the cache used by fetch_feed, for specific users to force an update, by looking for the transient and deleting it before calling fetch_feed.
if ( $this->bypass ) {
$identifier = md5($this->feedUrl);
$cacheKey = 'feed_' . $identifier;
$cachedResult = get_transient($cacheKey);
delete_transient($cacheKey);
}
$feedData = fetch_feed($this->feedUrl);
This however doesn't generate the correct transient key. They key in the database will be feed_2e798d9381cdbac2bb90151bf553c129 but this code is giving me feed_3f88b9c0e4a4ed755f0216b12b320fa5.
Is there a way to get the correct key from the url, or is there a method to delete the transient key via url?
Share Improve this question edited Jul 30, 2023 at 20:45 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jul 30, 2023 at 20:38 Picard102Picard102 9331 gold badge10 silver badges23 bronze badges1 Answer
Reset to default 1SimplePie
does not necessarily use the exact feed URL that was passed to fetch_feed()
– see SimplePie::get_cache_filename()
, but yes, WordPress adds the feed_
prefix to the transient key.
So you can instead try using the wp_feed_options
hook to get the correct transient key and then delete the existing transient.
$bypass = $this->bypass;
add_action(
'wp_feed_options',
function ( $feed ) use ( &$bypass ) {
if ( $bypass ) {
$cache_key = 'feed_' . $feed->get_cache_filename( $feed->feed_url );
delete_transient( $cache_key );
$bypass = false; // transient deleted, so reset this to the default
}
}
);
$feedData = fetch_feed( $this->feedUrl );
If you do not need to update the cached data, i.e. you just wanted to bypass reading from the cache, then you could simply use function ( $feed ) use ( &$bypass ) { $feed->cache = ! $bypass; }
.
本文标签: feedBypass fetchfeed cache
版权声明:本文标题:feed - Bypass fetch_feed cache 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736855260a1955685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论