Swiftgram/submodules/Postbox/Sources/CachedItemView.swift
2021-09-22 01:56:45 +03:00

32 lines
922 B
Swift

import Foundation
final class MutableCachedItemView: MutablePostboxView {
private let id: ItemCacheEntryId
fileprivate var value: PostboxCoding?
init(postbox: PostboxImpl, id: ItemCacheEntryId) {
self.id = id
self.value = postbox.itemCacheTable.retrieve(id: id, metaTable: postbox.itemCacheMetaTable)
}
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
if transaction.updatedCacheEntryKeys.contains(self.id) {
self.value = postbox.itemCacheTable.retrieve(id: id, metaTable: postbox.itemCacheMetaTable)
return true
}
return false
}
func immutableView() -> PostboxView {
return CachedItemView(self)
}
}
public final class CachedItemView: PostboxView {
public let value: PostboxCoding?
init(_ view: MutableCachedItemView) {
self.value = view.value
}
}