PluginProbe ʕ •ᴥ•ʔ
Aruba HiSpeed Cache / 3.0.15
Aruba HiSpeed Cache v3.0.15
3.0.15 3.0.14 3.0.13 1.2.4 1.2.5 1.2.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.19 2.0.20 2.0.21 2.0.22 2.0.23 2.0.24 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3
aruba-hispeed-cache / src / Purger / WpPurger.php
aruba-hispeed-cache / src / Purger Last commit date
AbstractPurger.php 4 days ago WpPurger.php 4 days ago
WpPurger.php
203 lines
1 <?php //@phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
2 /**
3 * ArubaHiSpeedCacheWpPurger
4 * php version 7.4
5 *
6 * @category Wordpress-plugin
7 * @package Aruba-HiSpeed-Cache
8 * @author Aruba Developer <hispeedcache.developer@aruba.it>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link \ArubaHiSpeedCache\Run_Aruba_Hispeed_cache()
11 * @since 1.1.3
12 */
13
14 namespace ArubaSPA\HiSpeedCache\Purger;
15
16 // Unqualified defined() on purpose: inside a namespace PHP still resolves it to the
17 // global function, and Plugin Check only recognises this exact guard shape.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 if ( ! \class_exists( __NAMESPACE__ . 'WpPurger' ) ) {
23 // phpcs:disable WordPress.NamingConventions
24 /**
25 * Undocumented class
26 */
27 class WpPurger extends AbstractPurger {
28
29 /**
30 * Purge the cache of a single page
31 *
32 * @param string $url The url to purge.
33 * @return void
34 */
35 public function purgeUrl( $url ) {
36 // $site_url = $this->getParseSiteUrl();
37 // $host = $site_url['host'];
38
39 $_url = \filter_var( $url, FILTER_SANITIZE_URL );
40
41 // Logger.
42 if(class_exists('ArubaSPA\HiSpeedCache\Debug\Logger')) {
43 // Logger.
44 AHSC_log( 'targhet ' . $_url, 'purgeUrl()' );
45 // Logger.
46 }
47 // Logger.
48
49 $this->doRemoteGet( $_url );
50
51 \delete_expired_transients(true);
52 $this->flush_wp_object_cache();
53
54 $this->cache_warmer();
55 }
56
57 /**
58 * Purge the cache of a list of pages
59 *
60 * @param array $urls The urls to purge.
61 * @return void
62 */
63 public function purgeUrls( $urls ) {
64 foreach ( $urls as $url ) {
65 $this->doRemoteGet( $url );
66
67 // Logger.
68 if(class_exists('ArubaSPA\HiSpeedCache\Debug\Logger')) {
69 // Logger.
70 AHSC_log( 'targhet ' . $url, 'purgeUrl()' );
71 // Logger.
72 }
73 // Logger.
74 }
75
76
77 \delete_expired_transients(true);
78 $this->flush_wp_object_cache();
79
80 $this->cache_warmer();
81 }
82
83 /**
84 * Purge the alla chace of site
85 *
86 * @return void
87 */
88 public function purgeAll() {
89 // Logger.
90 global $logger;
91
92 if(class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger')) {
93 // Logger.
94 AHSC_log( 'targhet /', 'purgeAll()' );
95 // Logger.
96 }
97
98 $this->doRemoteGet( '/' );
99
100 \delete_expired_transients(true);
101 $this->flush_wp_object_cache();
102
103 $this->cache_warmer();
104 }
105
106 /**
107 * DoRemoteGet
108 *
109 * @param string $target path to purge.
110 *
111 * @return void
112 */
113 public function doRemoteGet( $target = '/' ) {
114 $purgeUrl = $this->preparePurgeRequestUri( $target );
115
116 $blog_id = null;
117
118 if ( is_multisite() ) {
119 $blog_id = \get_current_blog_id();
120 }
121
122 $host = \wp_parse_url( \get_site_url( $blog_id ) );
123 $host = $host['host'];
124
125 // Logger.
126 global $logger;
127
128 if(class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger')) {
129 // Logger.
130 AHSC_log( $purgeUrl, '_targhet' );
131 // Logger.
132 }
133 // Logger.
134
135 \wp_remote_get(
136 $purgeUrl,
137 array(
138 'timeout' => $this->timeOut,
139 'headers' => array(
140 'Host' => $host,
141 ),
142 )
143 );
144 }
145
146 /**
147 * Whap form wp_cache_flush.
148 *
149 * @see https://developer.wordpress.org/reference/functions/wp_cache_flush/.
150 *
151 * @return bool
152 */
153 public function flush_wp_object_cache() {
154 $wp_object_cache = \wp_cache_flush();
155 if ( $wp_object_cache ) {
156 // Logger.
157 global $logger;
158
159 if(class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger') ) {
160 // Logger.
161 AHSC_log( 'flush wp_object_cache with success....' ,'flush_wp_object_cache');
162 // Logger.
163 }
164 // Logger.
165 }
166 return $wp_object_cache;
167 }
168
169 /**
170 * This function adds a transient that will be read with each subsequent request and will trigger the cache warming action.
171 * If the ahsc_cache_warmer option is set to true.
172 *
173 * @return void
174 */
175 public function cache_warmer() {
176 //$option = $this->container->get_service( 'ahsc_get_option' );
177 $cache_warmer = AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_cache_warmer'];// (bool) $option( 'ahsc_cache_warmer' );
178
179
180 if ( $cache_warmer ) {
181 $do_warmer=get_option('ahsc_do_cache_warmer',false);
182 //$do_warmer = ahsc_has_transient( 'ahsc_do_cache_warmer' );
183 $do_warmer_log_message = 'Transint warmer present';
184
185 if ( ! $do_warmer ) {
186 $do_warmer_log_message = 'Transint warmer non presente presente lo imposto : ';
187 update_option('ahsc_do_cache_warmer',true);
188 //$_r=ahsc_set_transient( 'ahsc_do_cache_warmer', \time(), MINUTE_IN_SECONDS );
189 //$do_warmer_log_message.=(string)$_r;
190 }
191 global $logger;
192 if(class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger') ) {
193 // Logger.
194 AHSC_log( $do_warmer_log_message, 'Cache Warmer' );
195 // Logger.
196 }
197 }
198 }
199
200 }
201 // phpcs:enable
202 }
203