int, 'bytes' => int, 'capped' => bool ) */ function wmguru_cache_stats() { $stats = array( 'files' => 0, 'bytes' => 0, 'capped' => false, ); $dir = wmguru_cache_dir(); if ( '' === $dir || ! is_dir( $dir ) ) { return $stats; } $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ) ); foreach ( $iterator as $file ) { if ( ! $file->isFile() || 'index.php' === $file->getFilename() ) { continue; } ++$stats['files']; $stats['bytes'] += $file->getSize(); if ( $stats['files'] >= 20000 ) { $stats['capped'] = true; break; } } return $stats; } /** * Remove key directories that no profile uses any more (older than a day, so * page-cached HTML that still points at the previous key keeps working). */ function wmguru_cleanup_stale() { $live = array(); foreach ( wmguru_get_profiles() as $profile ) { $live[] = wmguru_profile_key( $profile ); } foreach ( wmguru_cache_key_dirs() as $key_dir ) { if ( in_array( basename( $key_dir ), $live, true ) ) { continue; } if ( filemtime( $key_dir ) < time() - DAY_IN_SECONDS ) { wmguru_rrmdir( $key_dir ); } } } add_action( 'wmguru_daily_cleanup', 'wmguru_cleanup_stale' );