Closte.php
4 years ago
Cloudways.php
4 years ago
DreamHost.php
3 years ago
Flywheel.php
4 years ago
GoDaddyWPaaS.php
4 years ago
GridPane.php
4 years ago
Hosting.php
4 years ago
Kinsta.php
2 years ago
Pagely.php
2 years ago
PagelyCachePurge.php
4 years ago
Pantheon.php
2 years ago
Pressable.php
2 years ago
Raidboxes.php
2 years ago
RocketNet.php
3 years ago
Savvii.php
3 years ago
SiteGround.php
2 years ago
SpinupWp.php
2 years ago
Vimexx.php
3 years ago
WPEngine.php
2 years ago
WPX.php
3 years ago
WPmudev.php
2 years ago
Pressable.php
104 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Hosting; |
| 4 | |
| 5 | class Pressable extends Hosting { |
| 6 | const STAGE = "very_early"; |
| 7 | private $deviceTypes = ["mobile", "tablet", "desktop"]; |
| 8 | private $configuredCacheGroups = false; |
| 9 | |
| 10 | public static function detect() { |
| 11 | return isset($_SERVER["PRESSABLE_PROXIED_REQUEST"]) || strpos(gethostname(), "atomicsites.net") !== false; |
| 12 | } |
| 13 | |
| 14 | public function init($stage) { |
| 15 | if ($this->getHosting() == "pressable") { |
| 16 | switch ($stage) { |
| 17 | case "very_early": |
| 18 | $this->noCache(); |
| 19 | add_action('nitropack_cacheable_cache_headers', [$this, 'cacheShort']); |
| 20 | add_action('nitropack_cachehit_cache_headers', [$this, 'cacheLong']); |
| 21 | \NitroPack\ModuleHandler::initSemAcquire(); |
| 22 | return true; |
| 23 | case "early": |
| 24 | \NitroPack\ModuleHandler::initSemRelease(); |
| 25 | add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']); |
| 26 | add_action('nitropack_execute_purge_all', [$this, 'purgeAll']); |
| 27 | return; |
| 28 | default: |
| 29 | return; |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public function noCache() { |
| 35 | global $batcache; |
| 36 | |
| 37 | if (!empty($batcache) && is_object($batcache)) { |
| 38 | $batcache->max_age = 0; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public function cacheShort() { |
| 43 | global $batcache; |
| 44 | |
| 45 | if (!empty($batcache) && is_object($batcache)) { |
| 46 | $batcache->max_age = 30; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | public function cacheLong() { |
| 51 | global $batcache; |
| 52 | |
| 53 | if (!empty($batcache) && is_object($batcache)) { |
| 54 | $batcache->max_age = 300; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function purgeUrl($url) { |
| 59 | global $batcache; |
| 60 | |
| 61 | if (!$batcache || !is_object($batcache)) return; |
| 62 | |
| 63 | $urlObj = new \NitroPack\Url\Url($url); |
| 64 | if ($urlObj->getHost()) { |
| 65 | parse_str($urlObj->getQuery(), $query); |
| 66 | |
| 67 | foreach ($batcache->ignored_query_args as $arg) { |
| 68 | unset($query[$arg]); |
| 69 | } |
| 70 | ksort($query); |
| 71 | |
| 72 | $keys = array( |
| 73 | 'host' => $urlObj->getHost(), |
| 74 | 'method' => "GET", |
| 75 | 'path' => $urlObj->getPath(), |
| 76 | 'query' => $query, |
| 77 | 'extra' => [] |
| 78 | ); |
| 79 | |
| 80 | if ( isset( $batcache->origin ) ) { |
| 81 | $keys['origin'] = $batcache->origin; |
| 82 | } |
| 83 | |
| 84 | if ( $urlObj->getScheme() == "https" ) |
| 85 | $keys['ssl'] = true; |
| 86 | |
| 87 | wp_cache_init(); |
| 88 | $batcache->configure_groups(); |
| 89 | |
| 90 | foreach ($this->deviceTypes as $deviceType) { |
| 91 | $keys["extra"] = [$deviceType]; |
| 92 | $url_key = md5(serialize($keys)); |
| 93 | |
| 94 | wp_cache_delete( $url_key, $batcache->group ); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | public function purgeAll() { |
| 100 | wp_cache_flush(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 |