Clears image cache with “Clear Cache…” option in Settings

Also increases image cache size to 512MB.
This commit is contained in:
Riley Testut
2023-12-07 16:58:39 -06:00
parent 0d9de4814d
commit 6a37957121
2 changed files with 40 additions and 0 deletions

View File

@@ -15,6 +15,8 @@ import AltStoreCore
import AltSign
import Roxas
import Nuke
extension UIApplication: LegacyBackgroundFetching {}
extension AppDelegate
@@ -57,6 +59,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
AnalyticsManager.shared.start()
self.setTintColor()
self.prepareImageCache()
ServerManager.shared.startDiscovering()
@@ -145,6 +148,33 @@ private extension AppDelegate
self.window?.tintColor = .altPrimary
}
func prepareImageCache()
{
// Avoid caching responses twice.
DataLoader.sharedUrlCache.diskCapacity = 0
let pipeline = ImagePipeline { configuration in
do
{
let dataCache = try DataCache(name: "io.altstore.Nuke")
dataCache.sizeLimit = 512 * 1024 * 1024 // 512MB
configuration.dataCache = dataCache
}
catch
{
Logger.main.error("Failed to create image disk cache. Falling back to URL cache. \(error.localizedDescription, privacy: .public)")
}
}
ImagePipeline.shared = pipeline
if let dataCache = ImagePipeline.shared.configuration.dataCache as? DataCache, #available(iOS 15, *)
{
Logger.main.info("Current image cache size: \(dataCache.totalSize.formatted(.byteCount(style: .file)), privacy: .public)")
}
}
func open(_ url: URL) -> Bool
{
if url.isFileURL