Twitter\WordPress\Shortcodes\EmbeddedTweet::oEmbedCacheKey PHP Method

oEmbedCacheKey() public static method

Construct a cache key for the oEmbed response. Account for query parameters needing to bust cache
Since: 1.0.0
public static oEmbedCacheKey ( array $query_parameters ) : string
$query_parameters array oEmbed API query parameters
return string cache key
    public static function oEmbedCacheKey(array $query_parameters)
    {
        if (!(isset($query_parameters['id']) && $query_parameters['id'])) {
            return '';
        }
        $key_pieces = array(self::SHORTCODE_TAG, $query_parameters['id']);
        // separate cache for each explicitly-defined display language
        if (isset($query_parameters['lang']) && $query_parameters['lang']) {
            $key_pieces[] = $query_parameters['lang'];
        }
        $customizations = static::getOEmbedCacheKeyCustomParameters($query_parameters);
        if ($customizations) {
            $key_pieces[] = $customizations;
        }
        return implode('_', $key_pieces);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Test building a unique cache key for requested query parameters
  *
  * @since 1.0.0
  *
  * @covers ::oEmbedCacheKey
  * @small
  *
  * @return void
  */
 public function testOEmbedCacheKey()
 {
     $this->assertEquals('tweet_20', \Twitter\WordPress\Shortcodes\EmbeddedTweet::oEmbedCacheKey(array('id' => '20')), 'Unexpected cache key');
 }