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