- $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
- if ( $this->usecache ) {
- $cache = get_post_meta( $post_ID, $cachekey, true );
+ $key_suffix = md5( $url . serialize( $attr ) );
+ $cachekey = '_oembed_' . $key_suffix;
+ $cachekey_time = '_oembed_time_' . $key_suffix;
+
+ /**
+ * Filter the oEmbed TTL value (time to live).
+ *
+ * @since 4.0.0
+ *
+ * @param int $time Time to live (in seconds).
+ * @param string $url The attempted embed URL.
+ * @param array $attr An array of shortcode attributes.
+ * @param int $post_ID Post ID.
+ */
+ $ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID );
+
+ $cache = get_post_meta( $post_ID, $cachekey, true );
+ $cache_time = get_post_meta( $post_ID, $cachekey_time, true );
+
+ if ( ! $cache_time ) {
+ $cache_time = 0;
+ }
+
+ $cached_recently = ( time() - $cache_time ) < $ttl;