Add debug environment variable to disable image caching
This commit is contained in:
parent
6965a4c374
commit
9b85090884
|
@ -89,6 +89,13 @@
|
|||
isEnabled = "YES">
|
||||
</CommandLineArgument>
|
||||
</CommandLineArguments>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "DISABLE_IMAGE_CACHE"
|
||||
value = "1"
|
||||
isEnabled = "NO">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
|
|
|
@ -15,6 +15,12 @@ class ImageCache {
|
|||
static let headers = ImageCache(name: "Headers", memoryExpiry: .seconds(60 * 5), diskExpiry: .seconds(60 * 60))
|
||||
static let attachments = ImageCache(name: "Attachments", memoryExpiry: .seconds(60 * 2))
|
||||
static let emojis = ImageCache(name: "Emojis", memoryExpiry: .seconds(60 * 5), diskExpiry: .seconds(60 * 60))
|
||||
|
||||
#if DEBUG
|
||||
private static let disableCaching = ProcessInfo.processInfo.environment.keys.contains("DISABLE_IMAGE_CACHE")
|
||||
#else
|
||||
private static let disableCaching = false
|
||||
#endif
|
||||
|
||||
private let cache: Cache<Data>
|
||||
|
||||
|
@ -38,7 +44,8 @@ class ImageCache {
|
|||
|
||||
func get(_ url: URL, completion: ((Data?) -> Void)?) -> Request? {
|
||||
let key = url.absoluteString
|
||||
if let data = try? cache.object(forKey: key) {
|
||||
if !ImageCache.disableCaching,
|
||||
let data = try? cache.object(forKey: key) {
|
||||
completion?(data)
|
||||
return nil
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue