| @@ -34,18 +34,20 @@ | ||
| 34 | 34 | function version( $args, $assoc_args ) { |
| 35 | 35 | $this->setupCliEnvironment( $args, $assoc_args ); |
| 36 | 36 | |
| 37 | 37 | global $wp_object_cache; |
| 38 | - $igbinary = function_exists( 'igbinary_serialize' ) && function_exists( 'igbinary_unserialize' ) | |
| 39 | - ? __( 'available', 'sqlite-object-cache' ) | |
| 38 | + $igbinary = function_exists( 'igbinary_serialize' ) | |
| 39 | + ? phpversion( 'igbinary' ) | |
| 40 | 40 | : __( 'unavailable', 'sqlite-object-cache' ); |
| 41 | + $force_serialize = defined( 'WP_SQLITE_OBJECT_CACHE_SERIALIZE' ) && WP_SQLITE_OBJECT_CACHE_SERIALIZE; | |
| 42 | + $igbinary .= $force_serialize ? esc_html__( '(disabled by WP_SQLITE_OBJECT_CACHE_SERIALIZE)', 'sqlite-object-cache' ) : ''; | |
| 41 | 43 | |
| 42 | 44 | if ( method_exists( $wp_object_cache, 'sqlite_get_version' ) ) { |
| 43 | 45 | $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' ), | |
| 46 | + /* translators: 1: version for sqlite 2: version for plugin 3: igbinary --- for WP-CLI */ | |
| 47 | + __( 'Versions: Plugin: %2$s SQLite: %1$s igbinary: %3$s.', 'sqlite-object-cache' ), | |
| 46 | 48 | $wp_object_cache->sqlite_get_version(), |
| 47 | - '1.4.1', | |
| 49 | + '1.6.0', | |
| 48 | 50 | $igbinary ); |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | WP_CLI::log( $this->commentPrefix . $msg ); |
| @@ -79,9 +81,9 @@ | ||
| 79 | 81 | $sizes = $wp_object_cache->sqlite_sizes(); |
| 80 | 82 | $msgs = array(); |
| 81 | 83 | |
| 82 | 84 | /* 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 ) ); | |
| 85 | + $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 | 86 | /* translators: 1: size of .sqlite database file free space in MiB. --- for WP-CLI */ |
| 85 | 87 | $msgs[] = sprintf( __( 'Free: %sMiB', 'sqlite-object-cache' ), number_format_i18n( $sizes['page_size'] * $sizes['free_pages'] / ( 1024.0 * 1024.0 ), 3 ) ); |
| 86 | 88 | $mmapsize = $sizes['mmap_size']; |
| 87 | 89 | if ( $mmapsize > 0 ) { |
| @@ -107,9 +109,9 @@ | ||
| 107 | 109 | $earliest = PHP_INT_MAX; |
| 108 | 110 | $latest = PHP_INT_MIN; |
| 109 | 111 | } |
| 110 | 112 | if ( $length > 0 ) { |
| 111 | - /* translators: 1: number of cached items. --- for WP-CLI */ | |
| 113 | + /* translators: 1: size of cached items in MiB. --- for WP-CLI */ | |
| 112 | 114 | $msgs[] = sprintf( __( 'Cached Data Size %sMiB', 'sqlite-object-cache' ), number_format_i18n( $length / ( 1024.0 * 1024.0 ), 3 ) ); |
| 113 | 115 | } |
| 114 | 116 | if ( $count > 0 ) { |
| 115 | 117 | /* translators: 1: number of cached items. --- for WP-CLI */ |
| @@ -114,8 +116,9 @@ | ||
| 114 | 116 | if ( $count > 0 ) { |
| 115 | 117 | /* translators: 1: number of cached items. --- for WP-CLI */ |
| 116 | 118 | $msgs[] = sprintf( __( 'Item Count: %s', 'sqlite-object-cache' ), number_format_i18n( $count ) ); |
| 117 | 119 | } |
| 120 | + | |
| 118 | 121 | if ( $earliest <= $latest ) { |
| 119 | 122 | /* translators: 1 start time 2 end time both in localized format. --- for WP-CLI */ |
| 120 | 123 | $msgs[] = sprintf( __( 'Expirations: %1$s to %2$s.', 'sqlite-object-cache' ), |
| 121 | 124 | $this->format_datestamp( $earliest ), $this->format_datestamp( $latest ) ); |
| @@ -233,23 +236,23 @@ | ||
| 233 | 236 | WP_CLI::error( $this->commentPrefix . __( 'Too many args. "sqlite-object-cache retain 4" retains measuremewnts for 4 hours.', 'sqlite-object-cache' ) ); |
| 234 | 237 | return; |
| 235 | 238 | } |
| 236 | 239 | list( $options, $old_samplerate ) = $this->get_one_option( 'retainmeasurements' ); |
| 237 | - $old_retain = strval( ( $old_retain < 1 ) ? 1 : $old_retain ); | |
| 240 | + $old_samplerate = strval( ( $old_samplerate < 1 ) ? 1 : $old_samplerate ); | |
| 238 | 241 | |
| 239 | 242 | 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 ) { | |
| 243 | + $new_samplerate = strval( $args[0] ); | |
| 244 | + $new_samplerate = strval( ( $new_samplerate < 1 ) ? 1 : $new_samplerate ); | |
| 245 | + if ( $old_samplerate === $new_samplerate ) { | |
| 243 | 246 | /* translators: 1: retention time --- for WP-CLI */ |
| 244 | 247 | $msg = __( 'Performance measurement retention unchanged at %1$shr', 'sqlite_object_cache' ); |
| 245 | - $msg = sprintf( $msg, $new_retain ); | |
| 248 | + $msg = sprintf( $msg, $new_samplerate ); | |
| 246 | 249 | WP_CLI::log( $this->commentPrefix . $msg ); |
| 247 | 250 | } else { |
| 248 | 251 | /* translators: 1: new retention time 2:former time --- for WP-CLI */ |
| 249 | 252 | $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 = sprintf( $msg, $new_samplerate, $old_samplerate ); | |
| 254 | + $options['retainmeasurements'] = strval( $new_samplerate ); | |
| 252 | 255 | |
| 253 | 256 | update_option( 'sqlite_object_cache_settings', $options, true ); |
| 254 | 257 | WP_CLI::success( $this->commentPrefix . $msg ); |
| 255 | 258 | |
| @@ -256,9 +259,9 @@ | ||
| 256 | 259 | } |
| 257 | 260 | } else { |
| 258 | 261 | /* translators: 1: retention time --- for WP-CLI */ |
| 259 | 262 | $msg = __( 'Performance measurement retention is %1$shr', 'sqlite_object_cache' ); |
| 260 | - $msg = sprintf( $msg, $old_retain ); | |
| 263 | + $msg = sprintf( $msg, $old_samplerate ); | |
| 261 | 264 | WP_CLI::log( $this->commentPrefix . $msg ); |
| 262 | 265 | } |
| 263 | 266 | |
| 264 | 267 | } |
| @@ -305,8 +308,13 @@ | ||
| 305 | 308 | global $wp_object_cache; |
| 306 | 309 | if ( ! method_exists( $wp_object_cache, 'sqlite_get_size' ) ) { |
| 307 | 310 | return; |
| 308 | 311 | } |
| 312 | + | |
| 313 | + /* Always clean up old statistics. */ | |
| 314 | + list( $options, $retention ) = $this->get_one_option( 'retainmeasurements' ); | |
| 315 | + $wp_object_cache->sqlite_reset_statistics( $retention * HOUR_IN_SECONDS ); | |
| 316 | + | |
| 309 | 317 | $original_size = $wp_object_cache->sqlite_get_size(); |
| 310 | 318 | $current_size = $original_size; |
| 311 | 319 | /* Skip this if the current size is small enough. */ |
| 312 | 320 | if ( $current_size <= $threshold_size ) { |
| @@ -317,12 +325,11 @@ | ||
| 317 | 325 | |
| 318 | 326 | return; |
| 319 | 327 | } |
| 320 | 328 | |
| 321 | - | |
| 322 | - /* Remove expired items (transients mostly). --- For WP-CLI */ | |
| 329 | + /* Remove expired items (transients mostly). */ | |
| 323 | 330 | if ( $wp_object_cache->sqlite_remove_expired() ) { |
| 324 | - /* If anything was removed, get the size again. --- For WP-CLI */ | |
| 331 | + /* If anything was removed, get the size again. */ | |
| 325 | 332 | $current_size = $wp_object_cache->sqlite_get_size(); |
| 326 | 333 | |
| 327 | 334 | if ( $current_size < $original_size ) { |
| 328 | 335 | /* translators: 1: size removed 2: size remaining */ |
| @@ -336,24 +343,8 @@ | ||
| 336 | 343 | if ( $current_size <= $threshold_size ) { |
| 337 | 344 | return; |
| 338 | 345 | } |
| 339 | 346 | |
| 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 | 347 | /* Delete the least-recently-updated items to get to the target size. */ |
| 357 | 348 | $original_size = $current_size; |
| 358 | 349 | $wp_object_cache->sqlite_delete_old( $target_size, $current_size ); |
| 359 | 350 | $current_size = $wp_object_cache->sqlite_get_size(); |
| @@ -362,10 +353,8 @@ | ||
| 362 | 353 | $msg = __( '%1$01.1fMiB of least recently updated items removed from cache, leaving %2$01.1fMiB', 'sqlite_object_cache' ); |
| 363 | 354 | $msg = sprintf( $msg, ( $original_size - $current_size ) / ( 1024.0 * 1024.0 ), ( $current_size ) / ( 1024.0 * 1024.0 ) ); |
| 364 | 355 | WP_CLI::success( $this->commentPrefix . $msg ); |
| 365 | 356 | } |
| 366 | - | |
| 367 | - $wp_object_cache->sqlite_delete_old( $target_size, $current_size ); | |
| 368 | 357 | } |
| 369 | 358 | |
| 370 | 359 | private function get_one_option( |
| 371 | 360 | $name |