Skip to content

Commit

Permalink
add expires to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
MattRead committed Oct 1, 2014
1 parent d47b485 commit b169815
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dashboard.block.staticcache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<ul class="items">
<li class="item clear">
<span class="pct80"><?php _e('Cache Expiry' ); ?></span><span class="comments pct20"><?php echo $content->static_cache_expire; ?></span>
</li>

<li class="item clear">
<span class="pct80"><?php _e('Average page generation time' ); ?></span><span class="comments pct20"><?php echo $content->static_cache_average; ?> sec.</span>
</li>
Expand Down
29 changes: 29 additions & 0 deletions staticcache.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,37 @@ public function action_block_content_staticcache( Block $block, Theme $theme )
$block->static_cache_misses_pct = sprintf('%.0f', $total > 0 ? ($misses/$total)*100 : 0);
$block->static_cache_hits = $hits;
$block->static_cache_misses = $misses;
$block->static_cache_expire = $this->secs_to_human(Options::get('staticcache__expire', StaticCache::EXPIRE));
}

/*
* Convert seconds to human readable text.
*
*/
public function secs_to_human($secs)
{
$units = array(
"week" => 7*24*3600,
"day" => 24*3600,
"hour" => 3600,
"minute" => 60,
"second" => 1,
);

// specifically handle zero
if ( $secs == 0 ) return "0 seconds";

$s = "";
foreach ( $units as $name => $divisor ) {
if ( $quot = intval($secs / $divisor) ) {
$s .= "$quot $name";
$s .= (abs($quot) > 1 ? "s" : "") . ", ";
$secs -= $quot * $divisor;
}
}
return substr($s, 0, -2);
}

/**
* Ajax entry point for the 'clear cache data' action. Clears all stats and cache data
* and outputs a JSON encoded string message.
Expand Down

0 comments on commit b169815

Please sign in to comment.