1: <?php
2:
3: namespace Cloudflare\Zone;
4:
5: use Cloudflare\Api;
6: use Cloudflare\Zone;
7:
8: /**
9: * CloudFlare API wrapper
10: *
11: * Cache
12: *
13: * @author James Bell <[email protected]>
14: *
15: * @version 1
16: */
17: class Cache extends Api
18: {
19: /**
20: * Default permissions level
21: *
22: * @var array
23: */
24: protected $permission_level = ['read' => '#zone:read', 'edit' => '#zone:edit'];
25:
26: /**
27: * Purge all files (permission needed: #zone:edit)
28: * Remove ALL files from CloudFlare's cache
29: *
30: * @param string $identifier API item identifier tag
31: * @param bool|null $purge_everything A flag that indicates all resources in CloudFlare's cache should be removed.
32: * Note: This may have dramatic affects on your origin server load after performing this action. (true)
33: */
34: public function purge($identifier, $purge_everything = null)
35: {
36: $data = [
37: 'purge_everything' => $purge_everything,
38: ];
39:
40: return $this->delete('zones/'.$identifier.'/purge_cache', $data);
41: }
42:
43: /**
44: * Purge individual files (permission needed: #zone:edit)
45: * Remove one or more files from CloudFlare's cache
46: *
47: * @param string $identifier API item identifier tag
48: * @param array|null $files An array of URLs that should be removed from cache
49: * @param array|null $tags Any assets served with a Cache-Tag header that matches one of the provided values will be purged from the CloudFlare cache
50: */
51: public function purge_files($identifier, array $files = null, array $tags = null)
52: {
53: $data = [
54: 'files' => $files,
55: 'tags' => $tags,
56: ];
57:
58: return $this->delete('zones/'.$identifier.'/purge_cache', $data);
59: }
60: }
61: