PluginProbe
SQLite Object Cache / 1.6.2
SQLite Object Cache v1.6.2
1.6.5 trunk 0.1.7 1.0.0 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0 1.4.1 1.5.1 1.5.4 1.5.5 1.5.6 1.5.7 All 30 releases
← All changes | includes/cli.php +40 -50 1.4.11.6.2 View file →
@@ -3,8 +3,9 @@
3 3 /** @noinspection PhpUndefinedFunctionInspection */
4 4 /** @noinspection PhpUndefinedNamespaceInspection */
5 5 /** @noinspection PhpUndefinedClassInspection */
6 6
7 +if ( ! defined( 'ABSPATH' ) ) exit;
7 8 /**
8 9 * SQLite Object Cache plugin
9 10 *
10 11 * ## OPTIONS
@@ -34,18 +35,20 @@
34 35 function version( $args, $assoc_args ) {
35 36 $this->setupCliEnvironment( $args, $assoc_args );
36 37
37 38 global $wp_object_cache;
38 - $igbinary = function_exists( 'igbinary_serialize' ) && function_exists( 'igbinary_unserialize' )
39 - ? __( 'available', 'sqlite-object-cache' )
39 + $igbinary = function_exists( 'igbinary_serialize' )
40 + ? phpversion( 'igbinary' )
40 41 : __( 'unavailable', 'sqlite-object-cache' );
42 + $force_serialize = defined( 'WP_SQLITE_OBJECT_CACHE_SERIALIZE' ) && WP_SQLITE_OBJECT_CACHE_SERIALIZE;
43 + $igbinary .= $force_serialize ? esc_html__( '(disabled by WP_SQLITE_OBJECT_CACHE_SERIALIZE)', 'sqlite-object-cache' ) : '';
41 44
42 45 if ( method_exists( $wp_object_cache, 'sqlite_get_version' ) ) {
43 46 $msg = sprintf(
44 - /* translators: 1: version for sqlite 2: version for plugin 3: status of igbinary --- for WP-CLI */
45 - __( 'Versions: SQLite: %1$s Plugin: %2$s igbinary: %3$s.', 'sqlite-object-cache' ),
47 + /* translators: 1: version for sqlite 2: version for plugin 3: igbinary --- for WP-CLI */
48 + __( 'Versions: Plugin: %2$s SQLite: %1$s igbinary: %3$s.', 'sqlite-object-cache' ),
46 49 $wp_object_cache->sqlite_get_version(),
47 - '1.4.1',
50 + '1.6.2',
48 51 $igbinary );
49 52 }
50 53
51 54 WP_CLI::log( $this->commentPrefix . $msg );
@@ -79,9 +82,9 @@
79 82 $sizes = $wp_object_cache->sqlite_sizes();
80 83 $msgs = array();
81 84
82 85 /* translators: 1: size of .sqlite database file in MiB. --- for WP-CLI */
83 - $msgs[] = sprintf( __( 'SQLite File Size Total: %sMiB', 'sqlite-object-cache' ), number_format_i18n( $sizes['page_size'] * $sizes['total_pages'] / ( 1024.0 * 1024.0 ), 3 ) );
86 + $msgs[] = sprintf( __( 'SQLite File Size Total: %sMiB', 'sqlite-object-cache' ), number_format_i18n( $sizes['page_size'] * $sizes['total_pages'] / ( 1024.0 * 1024.0 ), 3 ) );
84 87 /* translators: 1: size of .sqlite database file free space in MiB. --- for WP-CLI */
85 88 $msgs[] = sprintf( __( 'Free: %sMiB', 'sqlite-object-cache' ), number_format_i18n( $sizes['page_size'] * $sizes['free_pages'] / ( 1024.0 * 1024.0 ), 3 ) );
86 89 $mmapsize = $sizes['mmap_size'];
87 90 if ( $mmapsize > 0 ) {
@@ -107,9 +110,9 @@
107 110 $earliest = PHP_INT_MAX;
108 111 $latest = PHP_INT_MIN;
109 112 }
110 113 if ( $length > 0 ) {
111 - /* translators: 1: number of cached items. --- for WP-CLI */
114 + /* translators: 1: size of cached items in MiB. --- for WP-CLI */
112 115 $msgs[] = sprintf( __( 'Cached Data Size %sMiB', 'sqlite-object-cache' ), number_format_i18n( $length / ( 1024.0 * 1024.0 ), 3 ) );
113 116 }
114 117 if ( $count > 0 ) {
115 118 /* translators: 1: number of cached items. --- for WP-CLI */
@@ -114,8 +117,9 @@
114 117 if ( $count > 0 ) {
115 118 /* translators: 1: number of cached items. --- for WP-CLI */
116 119 $msgs[] = sprintf( __( 'Item Count: %s', 'sqlite-object-cache' ), number_format_i18n( $count ) );
117 120 }
121 +
118 122 if ( $earliest <= $latest ) {
119 123 /* translators: 1 start time 2 end time both in localized format. --- for WP-CLI */
120 124 $msgs[] = sprintf( __( 'Expirations: %1$s to %2$s.', 'sqlite-object-cache' ),
121 125 $this->format_datestamp( $earliest ), $this->format_datestamp( $latest ) );
@@ -146,14 +150,14 @@
146 150 if ( 1 === count( $args ) ) {
147 151 $new_target_size = strval( $args[0] );
148 152 if ( $new_target_size === $old_target_size ) {
149 153 /* translators: 1: new target cache size --- for WP-CLI */
150 - $msg = __( 'Target cache size unchanged at %1$sMiB', 'sqlite_object_cache' );
154 + $msg = __( 'Target cache size unchanged at %1$sMiB', 'sqlite-object-cache' );
151 155 $msg = sprintf( $msg, $new_target_size );
152 156 WP_CLI::log( $this->commentPrefix . $msg );
153 157 } else {
154 158 /* translators: 1: new target cache size 2:former target cache size */
155 - $msg = __( 'Target cache size changed from %2$sMiB to %1$sMiB', 'sqlite_object_cache' );
159 + $msg = __( 'Target cache size changed from %2$sMiB to %1$sMiB', 'sqlite-object-cache' );
156 160 $msg = sprintf( $msg, $new_target_size, $old_target_size );
157 161 $options['target_size'] = strval( $new_target_size );
158 162 update_option( 'sqlite_object_cache_settings', $options, true );
159 163 WP_CLI::success( $this->commentPrefix . $msg );
@@ -159,9 +163,9 @@
159 163 WP_CLI::success( $this->commentPrefix . $msg );
160 164 }
161 165 } else {
162 166 /* translators: 1: target cache size */
163 - $msg = __( 'Target cache size is %1$sMiB', 'sqlite_object_cache' );
167 + $msg = __( 'Target cache size is %1$sMiB', 'sqlite-object-cache' );
164 168 $msg = sprintf( $msg, $old_target_size );
165 169 WP_CLI::log( $this->commentPrefix . $msg );
166 170 }
167 171
@@ -195,14 +199,14 @@
195 199 $new_samplerate = strval( ( $new_samplerate > 100 ) ? 100 : $new_samplerate );
196 200 $new_capture = ( '0' === $new_samplerate ) ? 'off' : 'on';
197 201 if ( $old_samplerate === $new_samplerate ) {
198 202 /* translators: 1: new sample rate 0-100 --- for WP-CLI */
199 - $msg = __( 'Performance measurement sample rate unchanged at %1$s%%', 'sqlite_object_cache' );
203 + $msg = __( 'Performance measurement sample rate unchanged at %1$s%%', 'sqlite-object-cache' );
200 204 $msg = sprintf( $msg, $new_samplerate );
201 205 WP_CLI::log( $this->commentPrefix . $msg );
202 206 } else {
203 207 /* translators: 1: new rate 2:former rate --- for WP-CLI */
204 - $msg = __( 'Performance measurement sample rate changed from %2$s%% to %1$s%%', 'sqlite_object_cache' );
208 + $msg = __( 'Performance measurement sample rate changed from %2$s%% to %1$s%%', 'sqlite-object-cache' );
205 209 $msg = sprintf( $msg, $new_samplerate, $old_samplerate );
206 210 $options['samplerate'] = strval( $new_samplerate );
207 211 $options['capture'] = $new_capture;
208 212
@@ -211,9 +215,9 @@
211 215
212 216 }
213 217 } else {
214 218 /* translators: 1: sample rate --- for WP-CLI */
215 - $msg = __( 'Performance measurement sample rate is %1$s%%', 'sqlite_object_cache' );
219 + $msg = __( 'Performance measurement sample rate is %1$s%%', 'sqlite-object-cache' );
216 220 $msg = sprintf( $msg, $old_samplerate );
217 221 WP_CLI::log( $this->commentPrefix . $msg );
218 222 }
219 223
@@ -233,23 +237,23 @@
233 237 WP_CLI::error( $this->commentPrefix . __( 'Too many args. "sqlite-object-cache retain 4" retains measuremewnts for 4 hours.', 'sqlite-object-cache' ) );
234 238 return;
235 239 }
236 240 list( $options, $old_samplerate ) = $this->get_one_option( 'retainmeasurements' );
237 - $old_retain = strval( ( $old_retain < 1 ) ? 1 : $old_retain );
241 + $old_samplerate = strval( ( $old_samplerate < 1 ) ? 1 : $old_samplerate );
238 242
239 243 if ( 1 === count( $args ) ) {
240 - $new_retain = strval( $args[0] );
241 - $new_retain = strval( ( $new_retain < 1 ) ? 1 : $new_retain );
242 - if ( $old_retain === $new_retain ) {
244 + $new_samplerate = strval( $args[0] );
245 + $new_samplerate = strval( ( $new_samplerate < 1 ) ? 1 : $new_samplerate );
246 + if ( $old_samplerate === $new_samplerate ) {
243 247 /* translators: 1: retention time --- for WP-CLI */
244 - $msg = __( 'Performance measurement retention unchanged at %1$shr', 'sqlite_object_cache' );
245 - $msg = sprintf( $msg, $new_retain );
248 + $msg = __( 'Performance measurement retention unchanged at %1$shr', 'sqlite-object-cache' );
249 + $msg = sprintf( $msg, $new_samplerate );
246 250 WP_CLI::log( $this->commentPrefix . $msg );
247 251 } else {
248 252 /* translators: 1: new retention time 2:former time --- for WP-CLI */
249 - $msg = __( 'Performance measurement retention changed from %2$shr to %1$shr', 'sqlite_object_cache' );
250 - $msg = sprintf( $msg, $new_retain, $old_retain );
251 - $options['retainmeasurements'] = strval( $new_retain );
253 + $msg = __( 'Performance measurement retention changed from %2$shr to %1$shr', 'sqlite-object-cache' );
254 + $msg = sprintf( $msg, $new_samplerate, $old_samplerate );
255 + $options['retainmeasurements'] = strval( $new_samplerate );
252 256
253 257 update_option( 'sqlite_object_cache_settings', $options, true );
254 258 WP_CLI::success( $this->commentPrefix . $msg );
255 259
@@ -255,10 +259,10 @@
255 259
256 260 }
257 261 } else {
258 262 /* translators: 1: retention time --- for WP-CLI */
259 - $msg = __( 'Performance measurement retention is %1$shr', 'sqlite_object_cache' );
260 - $msg = sprintf( $msg, $old_retain );
263 + $msg = __( 'Performance measurement retention is %1$shr', 'sqlite-object-cache' );
264 + $msg = sprintf( $msg, $old_samplerate );
261 265 WP_CLI::log( $this->commentPrefix . $msg );
262 266 }
263 267
264 268 }
@@ -263,9 +267,9 @@
263 267
264 268 }
265 269
266 270 /**
267 - * Flush the cache (delete all its entries). This briefly puts your site into maintenance mode.
271 + * Flush the cache (delete all its entries, including all transients). This briefly puts your site into maintenance mode.
268 272 */
269 273 function flush( $args, $assoc_args ) {
270 274 global $wp_object_cache;
271 275 if ( method_exists( $wp_object_cache, 'flush' ) ) {
@@ -305,14 +309,19 @@
305 309 global $wp_object_cache;
306 310 if ( ! method_exists( $wp_object_cache, 'sqlite_get_size' ) ) {
307 311 return;
308 312 }
313 +
314 + /* Always clean up old statistics. */
315 + list( $options, $retention ) = $this->get_one_option( 'retainmeasurements' );
316 + $wp_object_cache->sqlite_reset_statistics( $retention * HOUR_IN_SECONDS );
317 +
309 318 $original_size = $wp_object_cache->sqlite_get_size();
310 319 $current_size = $original_size;
311 320 /* Skip this if the current size is small enough. */
312 321 if ( $current_size <= $threshold_size ) {
313 322 /* translators: 1: size of cache --- For WP-CLI */
314 - $msg = __( 'Cache contains %1$01.1fMiB, no cleanup performed', 'sqlite_object_cache' );
323 + $msg = __( 'Cache contains %1$01.1fMiB, no cleanup performed', 'sqlite-object-cache' );
315 324 $msg = sprintf( $msg, $original_size / ( 1024.0 * 1024.0 ) );
316 325 WP_CLI::log( $this->commentPrefix . $msg );
317 326
318 327 return;
@@ -317,17 +326,16 @@
317 326
318 327 return;
319 328 }
320 329
321 -
322 - /* Remove expired items (transients mostly). --- For WP-CLI */
330 + /* Remove expired items (transients mostly). */
323 331 if ( $wp_object_cache->sqlite_remove_expired() ) {
324 - /* If anything was removed, get the size again. --- For WP-CLI */
332 + /* If anything was removed, get the size again. */
325 333 $current_size = $wp_object_cache->sqlite_get_size();
326 334
327 335 if ( $current_size < $original_size ) {
328 336 /* translators: 1: size removed 2: size remaining */
329 - $msg = __( '%1$01.1fMiB of expired items removed from cache, leaving %2$01.1fMiB', 'sqlite_object_cache' );
337 + $msg = __( '%1$01.1fMiB of expired items removed from cache, leaving %2$01.1fMiB', 'sqlite-object-cache' );
330 338 $msg = sprintf( $msg, ( $original_size - $current_size ) / ( 1024.0 * 1024.0 ), ( $current_size ) / ( 1024.0 * 1024.0 ) );
331 339 WP_CLI::success( $this->commentPrefix . $msg );
332 340 }
333 341 }
@@ -336,24 +344,8 @@
336 344 if ( $current_size <= $threshold_size ) {
337 345 return;
338 346 }
339 347
340 - /* Clean up old statistics. */
341 - $original_size = $current_size;
342 - list( $options, $retention ) = $this->get_one_option( 'retainmeasurements' );
343 - $wp_object_cache->sqlite_reset_statistics( $retention * HOUR_IN_SECONDS );
344 - $current_size = $wp_object_cache->sqlite_get_size();
345 - if ( $current_size < $original_size ) {
346 - /* translators: 1: size removed 2: size remaining --- For WP-CLI */
347 - $msg = __( '%1$01.1fMiB of performance measurements removed from cache, leaving %2$01.1fMiB', 'sqlite_object_cache' );
348 - $msg = sprintf( $msg, ( $original_size - $current_size ) / ( 1024.0 * 1024.0 ), ( $current_size ) / ( 1024.0 * 1024.0 ) );
349 - WP_CLI::success( $this->commentPrefix . $msg );
350 - }
351 -
352 - if ( $current_size <= $threshold_size ) {
353 - return;
354 - }
355 -
356 348 /* Delete the least-recently-updated items to get to the target size. */
357 349 $original_size = $current_size;
358 350 $wp_object_cache->sqlite_delete_old( $target_size, $current_size );
359 351 $current_size = $wp_object_cache->sqlite_get_size();
@@ -358,14 +350,12 @@
358 350 $wp_object_cache->sqlite_delete_old( $target_size, $current_size );
359 351 $current_size = $wp_object_cache->sqlite_get_size();
360 352 if ( $current_size < $original_size ) {
361 353 /* translators: 1: size removed 2: size remaining --- For WP-CLI */
362 - $msg = __( '%1$01.1fMiB of least recently updated items removed from cache, leaving %2$01.1fMiB', 'sqlite_object_cache' );
354 + $msg = __( '%1$01.1fMiB of least recently updated items removed from cache, leaving %2$01.1fMiB', 'sqlite-object-cache' );
363 355 $msg = sprintf( $msg, ( $original_size - $current_size ) / ( 1024.0 * 1024.0 ), ( $current_size ) / ( 1024.0 * 1024.0 ) );
364 356 WP_CLI::success( $this->commentPrefix . $msg );
365 357 }
366 -
367 - $wp_object_cache->sqlite_delete_old( $target_size, $current_size );
368 358 }
369 359
370 360 private function get_one_option(
371 361 $name
@@ -403,9 +393,9 @@
403 393 * @return void
404 394 */
405 395 private function exit_maintenance_mode() {
406 396 $maintenanceFileName = ABSPATH . '.maintenance';
407 - unlink( $maintenanceFileName );
397 + wp_delete_file( $maintenanceFileName );
408 398 }
409 399
410 400 /**
411 401 * Format a UNIX timestamp using WP settings.