diff --git a/SignalMessaging/groups/GroupV2Params.swift b/SignalMessaging/groups/GroupV2Params.swift index b631eab8ce..400834ddc8 100644 --- a/SignalMessaging/groups/GroupV2Params.swift +++ b/SignalMessaging/groups/GroupV2Params.swift @@ -91,7 +91,12 @@ public extension GroupV2Params { return try uuid(forUuidCiphertext: uuidCiphertext) } - private static let decryptedUuidCache = LRUCache(maxSize: 256) + private static var maxGroupSize: Int { + return Int(RemoteConfig.groupsV2MaxGroupSizeHardLimit) + } + + private static let decryptedUuidCache = LRUCache(maxSize: Self.maxGroupSize, + nseMaxSize: Self.maxGroupSize) func uuid(forUuidCiphertext uuidCiphertext: UuidCiphertext) throws -> UUID { let cacheKey = (uuidCiphertext.serialize().asData + groupSecretParamsData) @@ -117,7 +122,8 @@ public extension GroupV2Params { return userId } - private static let decryptedProfileKeyCache = LRUCache(maxSize: 256) + private static let decryptedProfileKeyCache = LRUCache(maxSize: Self.maxGroupSize, + nseMaxSize: Self.maxGroupSize) func profileKey(forProfileKeyCiphertext profileKeyCiphertext: ProfileKeyCiphertext, uuid: UUID) throws -> Data { diff --git a/SignalServiceKit/src/Util/LRUCache.swift b/SignalServiceKit/src/Util/LRUCache.swift index 307a585e1b..c7e2313554 100644 --- a/SignalServiceKit/src/Util/LRUCache.swift +++ b/SignalServiceKit/src/Util/LRUCache.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2021 Open Whisper Systems. All rights reserved. +// Copyright (c) 2022 Open Whisper Systems. All rights reserved. // // An @objc wrapper around LRUCache. @@ -64,7 +64,6 @@ public class AnyLRUCache: NSObject { public class LRUCache { private let cache = NSCache() - private let maxSize: Int private let _resetCount = AtomicUInt(0) public var resetCount: UInt { _resetCount.get() @@ -73,15 +72,7 @@ public class LRUCache { public init(maxSize: Int, nseMaxSize: Int = 0, shouldEvacuateInBackground: Bool = false) { - self.maxSize = { - if CurrentAppContext().isNSE { - let disableCacheInNSE = true - return disableCacheInNSE ? 0 : nseMaxSize - } else { - return maxSize - } - }() - self.cache.countLimit = maxSize + self.cache.countLimit = CurrentAppContext().isNSE ? nseMaxSize : maxSize if CurrentAppContext().isMainApp, shouldEvacuateInBackground { @@ -116,7 +107,7 @@ public class LRUCache { remove(key: key) return } - guard maxSize > 0 else { + guard cache.countLimit > 0 else { Logger.verbose("Using disabled cache.") return }