| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\data; |
| 3 |
|
| 4 |
/** |
| 5 |
* Embed cache related functionality. |
| 6 |
* |
| 7 |
* @author Epiphyt |
| 8 |
* @license GPL2 |
| 9 |
* @package epiphyt\Embed_Privacy |
| 10 |
* @since 1.11.0 |
| 11 |
*/ |
| 12 |
final class Embed_Cache { |
| 13 |
/** |
| 14 |
* Get an embed cache entry. |
| 15 |
* |
| 16 |
* @param string $url Embed URL |
| 17 |
* @return mixed Embed cache entry |
| 18 |
*/ |
| 19 |
public static function get( $url ) { |
| 20 |
return \get_transient( self::get_key( $url ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Get an embed cache key. |
| 25 |
* |
| 26 |
* @param string $url Embed URL |
| 27 |
* @return string Embed cache key |
| 28 |
*/ |
| 29 |
public static function get_key( $url ) { |
| 30 |
return 'embed_privacy_embed_' . \md5( $url ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Set an embed cache entry. |
| 35 |
* |
| 36 |
* @param string $url Embed URL |
| 37 |
* @param mixed $data Data to cache |
| 38 |
* @return bool Whether the value was set |
| 39 |
*/ |
| 40 |
public static function set( $url, $data ) { |
| 41 |
return \set_transient( self::get_key( $url ), $data, \WEEK_IN_SECONDS ); |
| 42 |
} |
| 43 |
} |
| 44 |
|