diff --git a/inc/class-cachify-backend.php b/inc/class-cachify-backend.php index 308b584..b4a39c4 100644 --- a/inc/class-cachify-backend.php +++ b/inc/class-cachify-backend.php @@ -65,4 +65,11 @@ public static function clear_cache(): void; * @param string $cache Cached content. */ public static function print_cache( bool $sig_detail, $cache ): void; + + /** + * Get the cache size + * + * @return integer Cache size in bytes. + */ + public static function get_stats(): int; } diff --git a/inc/class-cachify-db.php b/inc/class-cachify-db.php index 62566a5..3b5f508 100644 --- a/inc/class-cachify-db.php +++ b/inc/class-cachify-db.php @@ -138,7 +138,7 @@ public static function print_cache( bool $sig_detail, $cache ): void { /** * Get the cache size * - * @return int Column size + * @return integer Cache size in bytes. * * @since 2.0 */ diff --git a/inc/class-cachify-hdd.php b/inc/class-cachify-hdd.php index caf2984..5c87803 100644 --- a/inc/class-cachify-hdd.php +++ b/inc/class-cachify-hdd.php @@ -142,12 +142,12 @@ public static function print_cache( bool $sig_detail, $cache ): void { /** * Get the cache size * - * @return int Directory size + * @return integer Cache size in bytes. * * @since 2.0 */ public static function get_stats(): int { - return self::_dir_size( CACHIFY_CACHE_DIR ); + return (int) self::_dir_size( CACHIFY_CACHE_DIR ); } /** diff --git a/inc/class-cachify-memcached.php b/inc/class-cachify-memcached.php index eac53d8..7d93fce 100644 --- a/inc/class-cachify-memcached.php +++ b/inc/class-cachify-memcached.php @@ -154,14 +154,14 @@ public static function print_cache( bool $sig_detail, $cache ): void { /** * Get the cache size * - * @return mixed Cache size + * @return integer Cache size in bytes. * * @since 2.0.7 */ - public static function get_stats() { + public static function get_stats(): int { /* Server connect */ if ( ! self::_connect_server() ) { - return null; + return 0; } /* Info */ @@ -169,7 +169,7 @@ public static function get_stats() { /* No stats? */ if ( empty( $data ) ) { - return null; + return 0; } /* Get first key */ @@ -177,10 +177,10 @@ public static function get_stats() { /* Empty */ if ( empty( $data['bytes'] ) ) { - return null; + return 0; } - return $data['bytes']; + return (int) $data['bytes']; } /** diff --git a/inc/class-cachify-noop.php b/inc/class-cachify-noop.php index bc564af..496f355 100644 --- a/inc/class-cachify-noop.php +++ b/inc/class-cachify-noop.php @@ -104,7 +104,7 @@ public static function print_cache( bool $sig_detail, $cache ): void { /** * Get the cache size * - * @return int Column size + * @return integer Cache size in bytes. */ public static function get_stats(): int { return 0; diff --git a/inc/class-cachify-redis.php b/inc/class-cachify-redis.php index 7aa3f20..8e83454 100644 --- a/inc/class-cachify-redis.php +++ b/inc/class-cachify-redis.php @@ -133,12 +133,12 @@ public static function print_cache( bool $sig_detail, $cache ): void { /** * Get the cache size * - * @return integer Directory size + * @return integer Cache size in bytes. */ - public static function get_stats(): ?int { + public static function get_stats(): int { /* Server connect */ if ( ! self::_connect_server() ) { - return null; + return 0; } /* Info */ @@ -146,15 +146,15 @@ public static function get_stats(): ?int { /* No stats? */ if ( empty( $data ) ) { - return null; + return 0; } /* Empty */ if ( empty( $data['used_memory_dataset'] ) ) { - return null; + return 0; } - return $data['used_memory_dataset']; + return (int) $data['used_memory_dataset']; } /** diff --git a/inc/class-cachify.php b/inc/class-cachify.php index 591b7bf..0bc3b99 100644 --- a/inc/class-cachify.php +++ b/inc/class-cachify.php @@ -25,7 +25,7 @@ final class Cachify { /** * Caching method * - * @var object + * @var Cachify_Backend * * @since 2.0 */ @@ -602,12 +602,7 @@ public static function add_dashboard_count( array $items = array() ): array { $size = self::get_cache_size(); /* Caching method */ - $method = call_user_func( - array( - self::$method, - 'stringify_method', - ) - ); + $method = self::$method::stringify_method(); /* Output of the cache size */ $cachesize = ( 0 === $size ) @@ -655,12 +650,7 @@ public static function get_cache_size(): int { $size = get_transient( 'cachify_cache_size' ); if ( ! $size ) { /* Read */ - $size = (int) call_user_func( - array( - self::$method, - 'get_stats', - ) - ); + $size = self::$method::get_stats(); /* Save */ set_transient( @@ -1209,7 +1199,7 @@ public static function remove_page_cache_by_url( string $url ): void { } $hash = self::_cache_hash( $url ); - call_user_func( array( self::$method, 'delete_item' ), $hash, $url ); + self::$method::delete_item( $hash, $url ); /** * Call hook for further actions after cache has been flushed for a single page. @@ -1543,7 +1533,7 @@ public static function flush_total_cache( bool $clear_all_methods = false ): voi /* MEMCACHED */ Cachify_MEMCACHED::clear_cache(); } else { - call_user_func( array( self::$method, 'clear_cache' ) ); + self::$method::clear_cache(); } /** @@ -1609,11 +1599,7 @@ public static function set_cache( string $data ): string { */ $data = apply_filters( 'cachify_modify_output', $data, self::$method, self::_cache_hash(), self::_cache_expires() ); - call_user_func( - array( - self::$method, - 'store_item', - ), + self::$method::store_item( self::_cache_hash(), self::_minify_cache( $data ), self::_cache_expires(), @@ -1636,13 +1622,7 @@ public static function manage_cache(): void { } /* Data present in cache */ - $cache = call_user_func( - array( - self::$method, - 'get_item', - ), - self::_cache_hash() - ); + $cache = self::$method::get_item( self::_cache_hash() ); /* No cache? */ if ( empty( $cache ) ) { @@ -1651,14 +1631,7 @@ public static function manage_cache(): void { } /* Process cache */ - call_user_func( - array( - self::$method, - 'print_cache', - ), - self::_signature_details(), - $cache - ); + self::$method::print_cache( self::_signature_details(), $cache ); } /**