committed by
William Casarin
parent
f9c330aebf
commit
89bb293acd
@@ -5,17 +5,23 @@
|
|||||||
// Created by William Casarin on 2023-02-21.
|
// Created by William Casarin on 2023-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Combine
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import UIKit
|
||||||
|
|
||||||
class EventCache {
|
class EventCache {
|
||||||
private var events: [String: NostrEvent]
|
private var events: [String: NostrEvent] = [:]
|
||||||
private var replies: ReplyMap = ReplyMap()
|
private var replies = ReplyMap()
|
||||||
|
private var cancellable: AnyCancellable?
|
||||||
|
|
||||||
//private var thread_latest: [String: Int64]
|
//private var thread_latest: [String: Int64]
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.events = [:]
|
cancellable = NotificationCenter.default.publisher(
|
||||||
self.replies = ReplyMap()
|
for: UIApplication.didReceiveMemoryWarningNotification
|
||||||
|
).sink { [weak self] _ in
|
||||||
|
self?.prune()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parent_events(event: NostrEvent) -> [NostrEvent] {
|
func parent_events(event: NostrEvent) -> [NostrEvent] {
|
||||||
@@ -79,4 +85,8 @@ class EventCache {
|
|||||||
events[ev.id] = ev
|
events[ev.id] = ev
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func prune() {
|
||||||
|
events = [:]
|
||||||
|
replies.replies = [:]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user