Make WordPress Core

Opened 14 months ago

Closed 3 months ago

#62111 closed defect (bug) (duplicate)

The cache of the embed seems weird

Reported by: arthur791004's profile arthur791004 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Embeds Keywords: has-patch
Focuses: Cc:

Description

I found the cache of the embed seems weird.

Referring to https://github.com/WordPress/wordpress-develop/blob/7f4fd30dffdfe8d7d817c2cdb4ab98408f1c0add/src/wp-includes/class-wp-embed.php#L272, the cache won't be expired even if the value of $cached_recently is false because there is no place to set the $this->usecache to false except the cache_oembed function.

if ( $this->usecache || $cached_recently ) {
  ...
}

The goal of the cache_oembed function seems to reset all the cache to the latest value. However, when triggering the cache_oembed function, if the cache is not expired, the cache won't be force-updated.

As a result, it seems to be correct if we change the condition from || to &&. Does it make sense?

Attachments (1)

62111-embed-cache-fix.patch (541 bytes) - added by rahultank 3 months ago.
Confirmed bug in embed cache logic. The issue is on line 272 where || should be &&. Problem: cache_oembed() sets usecache=false to force refresh, but the OR condition still returns cached content if cached_recently=true. Solution: Change if ( $this->usecache || $cached_recently ) to if ( $this->usecache && $cached_recently ) This ensures cache is only used when both caching is enabled AND content is fresh. When forcing refresh, usecache=false bypasses cache regardless of age.

Download all attachments as: .zip

Change History (3)

This ticket was mentioned in PR #7434 on WordPress/wordpress-develop by @arthur791004.


14 months ago
#1

  • Keywords has-patch added

Fix the cache of the embed won't be expired forever

Trac ticket: https://core.trac.wordpress.org/ticket/62111

@rahultank
3 months ago

Confirmed bug in embed cache logic. The issue is on line 272 where || should be &&. Problem: cache_oembed() sets usecache=false to force refresh, but the OR condition still returns cached content if cached_recently=true. Solution: Change if ( $this->usecache || $cached_recently ) to if ( $this->usecache && $cached_recently ) This ensures cache is only used when both caching is enabled AND content is fresh. When forcing refresh, usecache=false bypasses cache regardless of age.

#2 @ocean90
3 months ago

  • Component changed from General to Embeds
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #37597.

Note: See TracTickets for help on using tickets.