From 2e779ac6f8f3d811b6110a423b4f3ae427dfe2d2 Mon Sep 17 00:00:00 2001 From: Pierre Lannoy Date: Tue, 11 Jan 2022 17:29:24 +0100 Subject: [PATCH] Removes internal cache introspection for performances reason. --- includes/system/class-cache.php | 109 -------------------------------- 1 file changed, 109 deletions(-) diff --git a/includes/system/class-cache.php b/includes/system/class-cache.php index 4de3f2e..efa5265 100644 --- a/includes/system/class-cache.php +++ b/includes/system/class-cache.php @@ -62,30 +62,6 @@ class Cache { */ private static $apcu_available = false; - /** - * Hits values. - * - * @since 1.0.0 - * @var array $hit Hits values. - */ - private static $hit = []; - - /** - * Miss values. - * - * @since 1.0.0 - * @var array $miss Miss values. - */ - private static $miss = []; - - /** - * Current (temporary) values. - * - * @since 1.0.0 - * @var array $current Current (temporary) values. - */ - private static $current = []; - /** * Initializes the class and set its properties. * @@ -125,18 +101,6 @@ public static function init() { } self::$apcu_pool_prefix = APCU_CACHE_PREFIX; self::$apcu_available = function_exists( 'apcu_delete' ) && function_exists( 'apcu_fetch' ) && function_exists( 'apcu_store' ); - add_action( 'shutdown', [ 'APCuManager\System\Cache', 'log_debug' ], 10, 0 ); - add_filter( 'perfopsone_icache_introspection', [ 'APCuManager\System\Cache', 'introspection' ] ); - } - - /** - * Get the introspection endpoint. - * - * @since 1.0.0 - */ - public static function introspection( $endpoints ) { - $endpoints[ APCM_SLUG ] = [ 'name' => APCM_PRODUCT_NAME, 'version' => APCM_VERSION, 'endpoint' => [ 'APCuManager\System\Cache', 'get_analytics' ] ]; - return $endpoints; } /** @@ -208,7 +172,6 @@ private static function normalized_item_name( $item_name ) { * @since 1.0.0 */ private static function get_for_full_name( $item_name ) { - $chrono = microtime( true ); $item_name = self::normalized_item_name( $item_name ); $found = false; if ( self::$apcu_available && Option::network_get( 'use_apcu', true ) ) { @@ -221,13 +184,8 @@ private static function get_for_full_name( $item_name ) { $found = false !== $result; } if ( $found ) { - self::$hit[] = [ - 'time' => microtime( true ) - $chrono, - 'size' => strlen( serialize( $result ) ), - ]; return $result; } else { - self::$current[ $item_name ] = $chrono; return null; } } @@ -294,12 +252,6 @@ private static function set_for_full_name( $item_name, $value, $ttl = 'default' } else { $result = set_transient( self::$pool_name . '_' . $item_name, $value, $expiration ); } - if ( array_key_exists( $item_name, self::$current ) ) { - self::$miss[] = [ - 'time' => microtime( true ) - self::$current[ $item_name ], - 'size' => strlen( serialize( $result ) ), - ]; - } } else { $result = false; } @@ -536,67 +488,6 @@ public static function get_med( $ttl_range ) { return $min + (int) round( $factor ); } - /** - * Get cache analytics. - * - * @return array The cache analytics. - * @since 1.0.0 - */ - public static function get_analytics() { - $result = []; - $hit_time = 0; - $hit_count = count( self::$hit ); - $hit_size = 0; - if ( 0 < $hit_count ) { - foreach ( self::$hit as $h ) { - $hit_time = $hit_time + $h['time']; - $hit_size = $hit_size + $h['size']; - } - $hit_time = $hit_time / $hit_count; - $hit_size = $hit_size / $hit_count; - } - $result['hit']['count'] = $hit_count; - $result['hit']['time'] = $hit_time; - $result['hit']['size'] = $hit_size; - $miss_time = 0; - $miss_count = count( self::$miss ); - $miss_size = 0; - if ( 0 < $miss_count ) { - foreach ( self::$miss as $h ) { - $miss_time = $miss_time + $h['time']; - $miss_size = $miss_size + $h['size']; - } - $miss_time = $miss_time / $miss_count; - $miss_size = $miss_size / $miss_count; - } - $result['miss']['count'] = $miss_count; - $result['miss']['time'] = $miss_time; - $result['miss']['size'] = $miss_size; - if ( wp_using_ext_object_cache() ) { - $result['type'] = 'object_cache'; - } elseif ( self::$apcu_available ) { - $result['type'] = 'apcu'; - } else { - $result['type'] = 'db_transient'; - } - return $result; - } - - /** - * Logs the cache analytics. - * - * @since 1.0.0 - */ - public static function log_debug() { - $analytics = self::get_analytics(); - $log = '[' . $analytics['type'] . ']'; - $log .= ' Hit count: ' . $analytics['hit']['count'] . ' Hit time: ' . round($analytics['hit']['time'] * 1000, 3) . 'ms Hit size: ' . Conversion::data_shorten( (int) $analytics['hit']['size'] ); - $log .= ' Miss count: ' . $analytics['miss']['count'] . ' Miss time: ' . round($analytics['miss']['time'] * 1000, 3) . 'ms Miss size: ' . Conversion::data_shorten( (int) $analytics['miss']['size'] ); - if ( 0 !== (int) $analytics['hit']['count'] || 0 !== (int) $analytics['miss']['count'] ) { - \DecaLog\Engine::eventsLogger( APCM_SLUG )->debug( $log ); - } - } - /** * Get the options infos for Site Health "info" tab. *