[wp-trac] [WordPress Trac] #14759: Improve the way oEmbed deals with caching

WordPress Trac noreply at wordpress.org
Mon Nov 25 16:30:18 UTC 2013


#14759: Improve the way oEmbed deals with caching
--------------------------+-----------------------------
 Reporter:  Viper007Bond  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Embeds        |     Version:  3.0.1
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+-----------------------------
Changes (by sanchothefat):

 * cc: robert@… (added)


Comment:

 I recently managed to brick a server by incorrectly assuming that caching
 would occur in the `WP_oEmbed` class. Confessional aside I make use of
 `wp_oembed_get()` fairly often and have had to implement my own transient
 based caches similar to Lee's in various plugins.

 So the issue is permanence (hence using post meta instead of transients)
 and using regular options is not possible because it would use up too much
 memory when auto loaded.

 Can I get some opinions on whether it's a horrible idea to think of oembed
 strings as media that can be stored as text files in the uploads folder?

 Here's my thinking:

  * `WP_oEmbed` checks cache using `file_exists` (php caches the result in
 stat cache)
  * Cache hits are returned using `$wp_fileSystem->get_contents()` or
 `readfile()` whichever is quicker
  * Cache misses are requested and written to disk with a name like
 `/uploads/oembeds/%provider%-md5(%url%+%args%).txt`
  * `cache_age` for each provider can be stored as an option
  * A wp-cron task cleans the expired oembed files based on `cache_age` and
 `filemtime()` using `glob('%provider%-*')`

 Is this just a bad idea? It would mean that embeds are available to all
 sites in a multisite installation. Some data on the number of files this
 could produce might show it to be impractical unless date based folders
 could be used.

 Let me know your thoughts on whether this worth coding up or if I should
 crawl back under my rock :)

--
Ticket URL: <http://core.trac.wordpress.org/ticket/14759#comment:25>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list