Files
JetsonMediaIOS/Jetson Media/cache/ImageCacheManager.swift
2025-08-17 22:08:25 +08:00

40 lines
1.2 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import UIKit
///
class ImageCacheManager {
static let shared = ImageCacheManager()
private let cache = NSCache<NSString, UIImage>()
//
private init() {
//
cache.totalCostLimit = 1024 * 1024 * 100 // 100MB
}
///
/// - Parameter url: URL
/// - Returns:
func getImage(for url: String) -> UIImage? {
return cache.object(forKey: url as NSString)
}
///
/// - Parameters:
/// - image:
/// - url: URL
func saveImage(_ image: UIImage, for url: String) {
cache.setObject(image, forKey: url as NSString)
}
/// URL
/// - Parameter url: URL
func removeImage(for url: String) {
cache.removeObject(forKey: url as NSString)
}
///
func clearAllCache() {
cache.removeAllObjects()
}
}