From 32711ef657a53ff0970bd606207281a74a62d9c1 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 25 Aug 2022 21:52:13 -0700 Subject: [PATCH] remove image cache --- .../Services/AudioSession/AudioSession.swift | 13 ---- .../Sources/Utils/ImageCache.swift | 63 ------------------- 2 files changed, 76 deletions(-) delete mode 100644 apple/OmnivoreKit/Sources/Utils/ImageCache.swift diff --git a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift index 781c481fd..6300379cd 100644 --- a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift +++ b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioSession.swift @@ -303,19 +303,6 @@ public class AudioSession: NSObject, ObservableObject, AVAudioPlayerDelegate { ] } -// if let imageURL = item?.imageURL, let cachedImage = ImageCache.shared[imageURL] { - //// #if os(iOS) - //// status = .loaded(image: Image(uiImage: cachedImage)) - //// #else - //// status = .loaded(image: Image(nsImage: cachedImage)) - //// #endif -// MPNowPlayingInfoCenter.default().nowPlayingInfo = [ -// // MPMediaItemPropertyArtwork: cachedImage, -// MPMediaItemPropertyArtist: item?.author ?? "Omnivore", -// MPMediaItemPropertyTitle: item?.title ?? "Your Omnivore Article" -// ] -// } - let commandCenter = MPRemoteCommandCenter.shared() commandCenter.playCommand.isEnabled = true diff --git a/apple/OmnivoreKit/Sources/Utils/ImageCache.swift b/apple/OmnivoreKit/Sources/Utils/ImageCache.swift deleted file mode 100644 index f05003969..000000000 --- a/apple/OmnivoreKit/Sources/Utils/ImageCache.swift +++ /dev/null @@ -1,63 +0,0 @@ -#if os(iOS) - import UIKit - - public typealias PlatformImage = UIImage -#elseif os(macOS) - import AppKit - - public typealias PlatformImage = NSImage -#endif - -/// Reference: https://www.onswiftwings.com/posts/reusable-image-cache/ - -public final class ImageCache { - public static let shared = ImageCache() - - public subscript(_ key: URL) -> PlatformImage? { - get { - image(key) - } - set { - insertImage(newValue, url: key) - } - } - - public func removeAllObjects() { - cache.removeAllObjects() - } - - private let queue = DispatchQueue(label: "app.omnivore.image.cache.queue", attributes: .concurrent) - private let cache = NSCache() - - private init() { - cache.totalCostLimit = 1024 * 1024 * 1024 * 50 // 50 MB - } - - private func image(_ url: URL) -> PlatformImage? { - var cachedImage: PlatformImage? - queue.sync { - cachedImage = cache.object(forKey: NSString(string: url.absoluteString)) - } - return cachedImage - } - - private func insertImage(_ image: PlatformImage?, url: URL) { - guard let image = image else { return } - queue.async(flags: .barrier) { - self.cache.setObject(image, forKey: NSString(string: url.absoluteString), cost: 1) - } - } -} - -private extension PlatformImage { - var diskSize: Int { - #if os(iOS) - guard let cgImage = cgImage else { return 0 } - return cgImage.bytesPerRow * cgImage.height - #elseif os(macOS) - // Instead of calculating the nsimage size just assume 250k - // which will allow for up to 200 images in the cache - (1024 * 1024) / 4 - #endif - } -}