forked from szepeviktor/w3-total-cache-fixed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cdn_CacheFlush.php
73 lines (62 loc) · 1.33 KB
/
Cdn_CacheFlush.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace W3TC;
/**
* CDN cache purge object
*/
/**
* class Cdn_CacheFlush
*/
class Cdn_CacheFlush {
/**
* Advanced cache config
*/
var $_config = null;
/**
* Array of urls to flush
*
* @var array
*/
private $flush_operation_requested = false;
/**
* PHP5 Constructor
*/
function __construct() {
$this->_config = Dispatcher::config();
}
/**
* Purges everything from CDNs that supports it
*/
function purge_all() {
$this->flush_operation_requested = true;
return true;
}
/**
* Purge a single url
*
* @param unknown $url
*/
function purge_url( $url ) {
$common = Dispatcher::component( 'Cdn_Core' );
$results = array();
$files = array();
$parsed = parse_url( $url );
$local_site_path = isset( $parsed['path'] )? ltrim( $parsed['path'], '/' ) : '';
$remote_path = $common->uri_to_cdn_uri( $local_site_path );
$files[] = $common->build_file_descriptor( $local_site_path, $remote_path );
$this->_flushed_urls[] = $url;
$common->purge( $files, false, $results );
}
/**
* Clears global and repeated urls
*/
function purge_post_cleanup() {
if ( $this->flush_operation_requested ) {
$common = Dispatcher::component( 'Cdn_Core' );
$results = array();
$common->purge_all( $results );
$count = 999;
$this->flush_operation_requested = false;
}
return $count;
}
}