Files
SpotX/Cache/cache_spotify_ru.ps1
amd64fox 9c22f6d34d Cache cleanup optimization
- Fixed slow client startup if cache purge was set
- Now there is a log file (Spotify/cache/log.txt) in which you can find information about the script to clear the cache.
- A little code optimization
2022-02-05 22:43:40 +03:00

43 lines
2.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<#
Имя: Очистка кеша Spotify.
Описание: Скрипт очищает устаревший кеш от прослушанной музыки в Spotify.
Срабатывает каждый раз когда вы полностью закрываете клиент (Если клиент был свернут в трей то скрипт не сработает).
Для папки APPDATA\Spotify\Data действует правило, все файлы кеша которые не использовадись
клиентом больше указанного количества дней будут удалены.
#>
$day = 7 # Количество дней после которых кеш считается устаревшим
# Очищаем папку \Data если найдет устаревший кеш
try {
If (!(Test-Path -Path $env:LOCALAPPDATA\Spotify\Data)) {
"$(Get-Date -uformat %D %T) Папка Local\Spotify\Data не найдена" | Out-File log.txt -append
exit
}
$check = Get-ChildItem $env:LOCALAPPDATA\Spotify\Data -File -Recurse | Where-Object lastaccesstime -lt (get-date).AddDays(-$day)
if ($check.Length -ge 1) {
$count = $check
$sum = $count | Measure-Object -Property Length -sum
if ($sum.Sum -ge 104434441824) {
$gb = "{0:N2} Gb" -f (($check | Measure-Object Length -s).sum / 1Gb)
"$(Get-Date -uformat %D %T) Удалено $gb устаревшего кеша" | Out-File log.txt -append
}
else {
$mb = "{0:N2} Mb" -f (($check | Measure-Object Length -s).sum / 1Mb)
"$(Get-Date -uformat %D %T) Удалено $mb устаревшего кеша" | Out-File log.txt -append
}
Get-ChildItem $env:LOCALAPPDATA\Spotify\Data -File -Recurse | Where-Object lastaccesstime -lt (get-date).AddDays(-$day) | Remove-Item
}
if ($check.Length -lt 1) {
"$(Get-Date -uformat %D %T) Устаревшего кеша не найдено" | Out-File log.txt -append
}
}
catch {
"$(Get-Date -uformat %D %T) $error[0].Exception" | Out-File log.txt -append
}
exit