知识卡片
失效广播要处理乱序丢失
共享缓存更新后通知各实例移除本地副本,可以减少旧值。通知可能丢失或乱序,物理时钟也可能偏移,需要版本或有效期等兜底;一次广播不等于所有本地缓存已被同步失效。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Distributed Caching · 查看原书依据
In a distributed environment, maintaining cache coherency requires careful coordination, as follows: class CoherentCacheManager: def update_data(self, key, value): # Update shared cache first self.l2_cache.set(key, value) # Broadcast invalidation to all instances self.broadcast_invalidation(key, time.now()) # Update local cache self.l1_cache.set(key, value) def handle_invalidation(self, message): key = message["key"] timestamp = message["timestamp"] if self.l1_cache.get_timestamp(key) < timestamp: self.l1_cache.invalidate(key) metrics.increment("cache_invalidation") Multi-level caching strategy Multi-level caching refers to a caching design that incorporates more than one level of cache between the application and the primary data store.