Skip to content

Commit

Permalink
Removes internal cache introspection for performances reason.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Lannoy committed Jan 11, 2022
1 parent c6453b8 commit 2e779ac
Showing 1 changed file with 0 additions and 109 deletions.
109 changes: 0 additions & 109 deletions includes/system/class-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 2e779ac

Please sign in to comment.