mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-18 19:23:43 +01:00
Clears image cache with “Clear Cache…” option in Settings
Also increases image cache size to 512MB.
This commit is contained in:
@@ -16,6 +16,8 @@ import AltSign
|
|||||||
import Roxas
|
import Roxas
|
||||||
import EmotionalDamage
|
import EmotionalDamage
|
||||||
|
|
||||||
|
import Nuke
|
||||||
|
|
||||||
extension UIApplication: LegacyBackgroundFetching {}
|
extension UIApplication: LegacyBackgroundFetching {}
|
||||||
|
|
||||||
extension AppDelegate
|
extension AppDelegate
|
||||||
@@ -60,6 +62,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
AnalyticsManager.shared.start()
|
AnalyticsManager.shared.start()
|
||||||
|
|
||||||
self.setTintColor()
|
self.setTintColor()
|
||||||
|
self.prepareImageCache()
|
||||||
|
|
||||||
SecureValueTransformer.register()
|
SecureValueTransformer.register()
|
||||||
|
|
||||||
@@ -143,6 +146,33 @@ private extension AppDelegate
|
|||||||
self.window?.tintColor = .altPrimary
|
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
|
func open(_ url: URL) -> Bool
|
||||||
{
|
{
|
||||||
if url.isFileURL
|
if url.isFileURL
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import AltStoreCore
|
import AltStoreCore
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
import Nuke
|
||||||
|
|
||||||
struct BatchError: ALTLocalizedError
|
struct BatchError: ALTLocalizedError
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -54,6 +57,8 @@ class ClearAppCacheOperation: ResultOperation<Void>
|
|||||||
{
|
{
|
||||||
super.main()
|
super.main()
|
||||||
|
|
||||||
|
self.clearNukeCache()
|
||||||
|
|
||||||
var allErrors = [Error]()
|
var allErrors = [Error]()
|
||||||
|
|
||||||
self.clearTemporaryDirectory { result in
|
self.clearTemporaryDirectory { result in
|
||||||
@@ -89,6 +94,12 @@ class ClearAppCacheOperation: ResultOperation<Void>
|
|||||||
|
|
||||||
private extension ClearAppCacheOperation
|
private extension ClearAppCacheOperation
|
||||||
{
|
{
|
||||||
|
func clearNukeCache()
|
||||||
|
{
|
||||||
|
guard let dataCache = ImagePipeline.shared.configuration.dataCache as? DataCache else { return }
|
||||||
|
dataCache.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
func clearTemporaryDirectory(completion: @escaping (Result<Void, Error>) -> Void)
|
func clearTemporaryDirectory(completion: @escaping (Result<Void, Error>) -> Void)
|
||||||
{
|
{
|
||||||
let intent = NSFileAccessIntent.writingIntent(with: FileManager.default.temporaryDirectory, options: [.forDeleting])
|
let intent = NSFileAccessIntent.writingIntent(with: FileManager.default.temporaryDirectory, options: [.forDeleting])
|
||||||
|
|||||||
Reference in New Issue
Block a user