Add a "clear cache" function
This commit is contained in:
@@ -145,6 +145,36 @@ final class MALibraryManager {
|
||||
return try? JSONDecoder().decode(T.self, from: data)
|
||||
}
|
||||
|
||||
/// Clears all cached library data from memory and disk.
|
||||
func clearAll() {
|
||||
artists = []
|
||||
albumArtists = []
|
||||
albums = []
|
||||
playlists = []
|
||||
podcasts = []
|
||||
favoriteURIs = []
|
||||
artistsOffset = 0
|
||||
albumArtistsOffset = 0
|
||||
albumsOffset = 0
|
||||
hasMoreArtists = true
|
||||
hasMoreAlbumArtists = true
|
||||
hasMoreAlbums = true
|
||||
lastArtistsRefresh = nil
|
||||
lastAlbumArtistsRefresh = nil
|
||||
lastAlbumsRefresh = nil
|
||||
lastPlaylistsRefresh = nil
|
||||
lastPodcastsRefresh = nil
|
||||
|
||||
let ud = UserDefaults.standard
|
||||
for key in ["lib.lastArtistsRefresh", "lib.lastAlbumArtistsRefresh",
|
||||
"lib.lastAlbumsRefresh", "lib.lastPlaylistsRefresh", "lib.lastPodcastsRefresh"] {
|
||||
ud.removeObject(forKey: key)
|
||||
}
|
||||
|
||||
try? FileManager.default.removeItem(at: cacheDirectory)
|
||||
try? FileManager.default.createDirectory(at: cacheDirectory, withIntermediateDirectories: true)
|
||||
}
|
||||
|
||||
private func markRefreshed(_ key: String) -> Date {
|
||||
let now = Date()
|
||||
UserDefaults.standard.set(now, forKey: key)
|
||||
|
||||
Reference in New Issue
Block a user