mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
- cache for AccountManagerSharedDataTable
This commit is contained in:
parent
03e68b6415
commit
2f9f4648d3
@ -1,12 +1,17 @@
|
||||
import Foundation
|
||||
|
||||
final class AccountManagerSharedDataTable: Table {
|
||||
|
||||
private var values:[ValueBoxKey : PreferencesEntry] = [:]
|
||||
|
||||
static func tableSpec(_ id: Int32) -> ValueBoxTable {
|
||||
return ValueBoxTable(id: id, keyType: .binary, compactValuesOnCreation: false)
|
||||
}
|
||||
|
||||
func get(key: ValueBoxKey) -> PreferencesEntry? {
|
||||
if let value = self.valueBox.get(self.table, key: key), let object = PostboxDecoder(buffer: value).decodeRootObject() as? PreferencesEntry {
|
||||
if let object = self.values[key] {
|
||||
return object
|
||||
} else if let value = self.valueBox.get(self.table, key: key), let object = PostboxDecoder(buffer: value).decodeRootObject() as? PreferencesEntry {
|
||||
return object
|
||||
} else {
|
||||
return nil
|
||||
@ -22,9 +27,13 @@ final class AccountManagerSharedDataTable: Table {
|
||||
encoder.encodeRootObject(value)
|
||||
self.valueBox.set(self.table, key: key, value: encoder.makeReadBufferAndReset())
|
||||
updatedKeys.insert(key)
|
||||
|
||||
self.values[key] = value
|
||||
|
||||
} else if self.get(key: key) != nil {
|
||||
self.valueBox.remove(self.table, key: key, secure: false)
|
||||
updatedKeys.insert(key)
|
||||
self.values.removeValue(forKey: key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user