Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions inc/class-cachify-backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion inc/class-cachify-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions inc/class-cachify-hdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
12 changes: 6 additions & 6 deletions inc/class-cachify-memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,33 +154,33 @@ 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 */
$data = self::$_memcached->getStats();

/* No stats? */
if ( empty( $data ) ) {
return null;
return 0;
}

/* Get first key */
$data = $data[ key( $data ) ];

/* Empty */
if ( empty( $data['bytes'] ) ) {
return null;
return 0;
}

return $data['bytes'];
return (int) $data['bytes'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/class-cachify-noop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions inc/class-cachify-redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,28 @@ 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 */
$data = self::$_redis->info( 'MEMORY' );

/* 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'];
}

/**
Expand Down
43 changes: 8 additions & 35 deletions inc/class-cachify.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Cachify {
/**
* Caching method
*
* @var object
* @var Cachify_Backend
*
* @since 2.0
*/
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}

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

/**
Expand Down