W3TCCdn_CloudFrontFsd_Engine

The W3 Total Cache W3TC Cdn CloudFrontFsd Engine class.

Defined (1)

The class is defined in the following location(s).

/Cdn_CloudFrontFsd_Engine.php  
  1. class Cdn_CloudFrontFsd_Engine { 
  2. private $access_key; 
  3. private $secret_key; 
  4. private $distribution_id; 
  5.  
  6.  
  7.  
  8. function __construct( $config = array() ) { 
  9. $this->access_key = $config['access_key']; 
  10. $this->secret_key = $config['secret_key']; 
  11. $this->distribution_id = $config['distribution_id']; 
  12.  
  13.  
  14.  
  15. function flush_urls( $urls ) { 
  16. if ( empty( $this->access_key ) || empty( $this->secret_key ) || 
  17. empty( $this->distribution_id ) ) 
  18. throw new \Exception( __( 'Access key not specified.', 'w3-total-cache' ) ); 
  19.  
  20. $api = new Cdn_CloudFrontFsd_Api( $this->access_key, $this->secret_key ); 
  21. $uris = array(); 
  22. foreach ( $urls as $url ) { 
  23. $parsed = parse_url( $url ); 
  24. $relative_url = 
  25. ( isset( $parsed['path'] ) ? $parsed['path'] : '/' ) . 
  26. ( isset( $parsed['query'] ) ? '?' . $parsed['query'] : '' ); 
  27. $uris[] = $relative_url; 
  28.  
  29. $api->invalidation_create( $this->distribution_id, $uris ); 
  30.  
  31.  
  32.  
  33. /** 
  34. * Flushes CDN completely 
  35. */ 
  36. function flush_all() { 
  37. if ( empty( $this->access_key ) || empty( $this->secret_key ) || 
  38. empty( $this->distribution_id ) ) 
  39. throw new \Exception( __( 'Access key not specified.', 'w3-total-cache' ) ); 
  40.  
  41. $api = new Cdn_CloudFrontFsd_Api( $this->access_key, $this->secret_key ); 
  42. $uris = array( '/*' ); 
  43.  
  44. $api->invalidation_create( $this->distribution_id, $uris );