mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
• Wired up the dev settings • Update logic to use an ed25519 key for the FileServer instead of an x25519 one • Updated the ReuploadUserDisplayPictureJob to wait for the first poll to succeed before running (to reduce config conflict issues) • Fixed a bug with the FileServer extend API call
48 lines
1.5 KiB
Swift
48 lines
1.5 KiB
Swift
// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
public final class StringCache: @unchecked Sendable {
|
|
/// `NSCache` has more nuanced memory management systems than just listening for `didReceiveMemoryWarningNotification`
|
|
/// and can clear out values gradually, it can also remove items based on their "cost" so is better suited than our custom `LRUCache`
|
|
///
|
|
/// Additionally `NSCache` is thread safe so we don't need to do any custom `ThreadSafeObject` work to interact with it
|
|
private let cache: NSCache<NSString, NSString> = NSCache()
|
|
|
|
public init(
|
|
name: String? = nil,
|
|
countLimit: Int? = nil,
|
|
totalCostLimit: Int? = nil
|
|
) {
|
|
if let name: String = name {
|
|
cache.name = name
|
|
}
|
|
|
|
if let countLimit: Int = countLimit {
|
|
cache.countLimit = countLimit
|
|
}
|
|
|
|
if let totalCostLimit: Int = totalCostLimit {
|
|
cache.totalCostLimit = totalCostLimit
|
|
}
|
|
}
|
|
|
|
// MARK: - Functions
|
|
|
|
public func object(forKey key: String) -> String? {
|
|
return cache.object(forKey: key as NSString) as? String
|
|
}
|
|
|
|
public func setObject(_ value: String, forKey key: String, cost: Int = 0) {
|
|
cache.setObject(value as NSString, forKey: key as NSString, cost: cost)
|
|
}
|
|
|
|
public func removeObject(forKey key: String) {
|
|
cache.removeObject(forKey: key as NSString)
|
|
}
|
|
|
|
public func removeAllObjects() {
|
|
cache.removeAllObjects()
|
|
}
|
|
}
|