WP_CLI
FileCache::prune
Remove all cached files except for the newest version of one.
Метод класса: FileCache{}
Хуков нет.
Возвращает
true|false.
Использование
$FileCache = new FileCache(); $FileCache->prune();
Код FileCache::prune() FileCache::prune WP-CLI 2.13.0-alpha
public function prune() {
if ( ! $this->enabled ) {
return false;
}
/** @var Finder $finder */
$finder = $this->get_finder()->sortByName();
$files_to_delete = [];
foreach ( $finder as $file ) {
$pieces = explode( '-', $file->getBasename( $file->getExtension() ) );
$timestamp = end( $pieces );
// No way to compare versions, do nothing.
if ( ! is_numeric( $timestamp ) ) {
continue;
}
$basename_without_timestamp = str_replace( '-' . $timestamp, '', $file->getBasename() );
// There's a file with an older timestamp, delete it.
if ( isset( $files_to_delete[ $basename_without_timestamp ] ) ) {
unlink( $files_to_delete[ $basename_without_timestamp ] );
}
$files_to_delete[ $basename_without_timestamp ] = $file->getRealPath();
}
return true;
}