Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23763 closed enhancement (duplicate)

Respect cache_age in oEmbed requests

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

Description

Currently oEmbed results are cached permanently in the postmeta table. These cached results never expire, and will be used forever, or until the WordPress post is updated. This is reasonable behaviour for resources that do not specify a cache_age - although I'd argue we should re-check the oEmbed source occassionally to cope with the case where the original resource is updated / removed etc.

The oEmbed documentation (http://oembed.com/ - section 2.3.4) lists cache_age as optional - so providers may not provide one. If it is provided, consumers still aren't bound to honour it ("Consumers may choose to use this value or not.") - so the current behaviour is perfectly in line with the spec, but I believe we can do better.

Several of the currently accepted oEmbed providers provide cache_ages (E.g. flickr, hulu, and twitter). Allowing cache_ages also helps when embedding information that can change over time (See http://wordpress.org/extend/plugins/github-embed/ and http://wordpress.org/extend/plugins/wporg-plugin-embed/ for example).

Patch to follow which:

  • Moves the caching of oEmbed responses from class-wp-embed.php down into class-oembed.php where it has access to the oEmbed response
  • Caches oEmbed HTML in transients rather than postmeta (The same embedded resource will be used no matter which post it is embedded in)
  • Sets a default cache period of 12 hours for oEmbed failures
  • Sets a default cache period of 30 days if no cache_age is specified
  • Sets a cache period according to cache_age if it is specified
  • Adds a new third argument to WP_oEmbed->get_html() and wp_oembed_get() to pass the value of $usecache through from classs-wp-embed.php

Open to discussion about the implementation details.

Attachments (1)

23763.patch (4.0 KB) - added by leewillis77 10 years ago.
Initial patch

Download all attachments as: .zip

Change History (4)

@leewillis77
10 years ago

Initial patch

#1 @helen
10 years ago

Related/duplicate: #14759. Also discussion on #17210 about storage location.

#2 @leewillis77
10 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Thanks - I think I'll close this in favour of #14759.

#3 @helen
10 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.