Skip to content

Commit

Permalink
Put transient variable in a function, remove spaces. (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dac514 authored and Ned Zimmerman committed Oct 20, 2018
1 parent 98060f5 commit 6bf46ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 1 addition & 10 deletions bin/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
set_time_limit( 0 );

// Stats page

$cache_key = \PressbooksStats\Stats\get_admin_page_html_cache_key();

delete_site_transient( $cache_key );

\PressbooksStats\Stats\cache_stats_admin_page();

$html = get_site_transient( \PressbooksStats\Stats\get_admin_page_html_cache_key() );

if ( empty( $html ) ) {
echo "Failed to cache the stats dashboard... \n";
} else {
Expand All @@ -25,14 +20,10 @@

// Network storage
if ( ! defined( 'PB_DISABLE_NETWORK_STORAGE' ) || ! PB_DISABLE_NETWORK_STORAGE ) {
$cache_key = 'pb_stats_network_storage';

$cache_key = \PressbooksStats\Stats\get_network_storage_cache_key();
delete_site_transient( $cache_key );

\PressbooksStats\Stats\cache_network_storage();

$storage = get_site_transient( $cache_key );

if ( empty( $storage ) ) {
echo "Failed to cache network storage data... \n";
} else {
Expand Down
12 changes: 10 additions & 2 deletions inc/stats/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,16 @@ function users_with_x_or_more_books( $x ) {
return $foo;
}

/**
* @return string
*/
function get_network_storage_cache_key() {
return 'pb_stats_network_storage';
}


function display_network_storage() {
$storage = get_site_transient( 'pb_stats_network_storage' );
$storage = get_site_transient( get_network_storage_cache_key() );
if ( ! empty( $storage ) ) {
$cached = '<!-- CACHED -->';
} else {
Expand All @@ -511,5 +519,5 @@ function calculate_network_storage() {
* Cache the network storage level
*/
function cache_network_storage() {
set_site_transient( 'pb_stats_network_storage', calculate_network_storage() );
set_site_transient( get_network_storage_cache_key(), calculate_network_storage() );
}

0 comments on commit 6bf46ed

Please sign in to comment.