mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
remove image cache
This commit is contained in:
parent
b70a8a8585
commit
32711ef657
2 changed files with 0 additions and 76 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<NSString, PlatformImage>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue