知识卡片
旁路与读穿责任不同
旁路缓存由应用先查缓存、未命中再读数据库并回填;读穿缓存将加载真源的责任封装在缓存组件内。两者都要处理加载失败与并发回填,差别在谁执行加载,而不是谁天然更一致。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Distributed Caching · 查看原书依据
In read-through caching, the cache acts as an intelligent intermediary between your application and the database. When the application requests data, it only needs to talk to the cache, as follows: # Without read-through caching def get_product(product_id): product = cache.get(product_id) if not product: product = database.get(product_id) cache.set(product_id, product) return product # With read-through caching def get_product(product_id): return cache_client.get(product_id) # Cache handles DB interaction if needed Write through caching Write-through cache is a caching strategy that simultaneously writes data to the cache and the main memory.