WP_CLI::get_cache
Method of the class: WP_CLI{}
No Hooks.
Returns
FileCache.
Usage
$result = WP_CLI::get_cache();
WP_CLI::get_cache() WP CLI::get cache code WP-CLI 2.13.0-alpha
public static function get_cache() {
static $cache;
if ( ! $cache ) {
$dir = Utils\get_cache_dir();
$ttl = getenv( 'WP_CLI_CACHE_EXPIRY' ) ? : 15552000;
$max_size = getenv( 'WP_CLI_CACHE_MAX_SIZE' ) ? : 314572800;
// 6 months, 300mb
$cache = new FileCache( $dir, $ttl, $max_size );
// Clean older files on shutdown with 1/50 probability.
// phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand -- no crypto and WP not loaded.
if ( 0 === mt_rand( 0, 50 ) ) {
register_shutdown_function(
function () use ( $cache ) {
$cache->clean();
}
);
}
}
return $cache;
}