From d153411f477e2c165fc90e05eafb5360686d085a Mon Sep 17 00:00:00 2001 From: Francesco Laffi Date: Fri, 11 Oct 2013 13:42:41 +0200 Subject: [PATCH] make WP_CLI::get_cache more readable and private --- php/class-wp-cli.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 7be4ac93..0476c43b 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -59,16 +59,22 @@ class WP_CLI { /** * @return FileCache */ - static function get_cache() { + private static function get_cache() { static $cache; if ( !$cache ) { - $home = getenv( 'HOME' ) ? : getenv( 'HOMEDRIVE' ) . '/' . getenv( 'HOMEPATH' ); + $home = getenv( 'HOME' ); + if ( !$home ) { + // sometime in windows $HOME is not defined + $home = getenv( 'HOMEDRIVE' ) . '/' . getenv( 'HOMEPATH' ); + } $dir = getenv( 'WP_CLI_CACHE_DIR' ) ? : "$home/.wp-cli/cache"; + // 6 months, 300mb - $cache = new FileCache( $dir, 15552000, 314572800); + $cache = new FileCache( $dir, 15552000, 314572800 ); - if (0 === mt_rand( 0, 50 ) ) { + // clean older files on shutdown with 1/50 probability + if ( 0 === mt_rand( 0, 50 ) ) { register_shutdown_function( function () use ( $cache ) { $cache->clean(); } ); -- 2.11.0