WP_CLI::get_cache()public staticWP-CLI 1.0

Метод класса: WP_CLI{}

No Hooks.

Return

FileCache.

Usage

$result = WP_CLI::get_cache();

Code of WP_CLI::get_cache() WP-CLI 2.7.0-alpha

public static function get_cache() {
	static $cache;

	if ( ! $cache ) {
		$home     = Utils\get_home_dir();
		$dir      = getenv( 'WP_CLI_CACHE_DIR' ) ? : "$home/.wp-cli/cache";
		$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;
}