mattermost-mobile/ios/Gekidou/Sources/Gekidou/Cache/ImageCache.swift
Elias Nahum 23cbf82353
Use LRU to cache the Avatar shown in push notifications (#7124)
* iOS switch from file cache to memory cache and use last_picture_update to update the avatar if needed

* Android switch from file cache to memory cache and use last_picture_update to update the avatar if needed, split function to multiple files and catch potential exceptions
2023-02-15 11:19:31 +02:00

31 lines
864 B
Swift

import Foundation
public final class ImageCache: ImageCacheType {
public static let `default` = ImageCache()
struct Config {
let countLimit: Int
let memoryLimit: Int
static let defaultConfig = Config(countLimit: 50, memoryLimit: 1024 * 1024 * 50)
}
lazy var imageCache: NSCache<NSString, NSData> = {
let cache = NSCache<NSString, NSData>()
cache.countLimit = config.countLimit
cache.totalCostLimit = config.memoryLimit
return cache
}()
lazy var keysCache: NSCache<NSString, NSString> = {
let cache = NSCache<NSString, NSString>()
cache.countLimit = config.countLimit
return cache
}()
let lock = NSLock()
let config: Config
private init(config: Config = Config.defaultConfig) {
self.config = config
}
}