Add debug environment variable to disable image caching

This commit is contained in:
Shadowfacts 2020-09-21 18:03:51 -04:00
parent 6965a4c374
commit 9b85090884
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 15 additions and 1 deletions

View File

@ -89,6 +89,13 @@
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "DISABLE_IMAGE_CACHE"
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"

View File

@ -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 {