多级缓存更新策略

Cache缓存更新模式:
1、Cache aside模式
2、Read through
3、Write through
4、Write behind Caching/Write back

Cache aside处理流程
a、读流程
app---> cache hit --->yes-->return data
--->no---->aget data from lower memory--->update cache--->return data
b、写流程
app--->write lower memory ------->invalid cache item

Read through、Write through模式通过cache同步完成次级缓存的读写,操作对应用是透明的。
1、cache与次级缓存的数据操作对应用是透明,应用逻辑简单。
2、cache与次级缓存的数据操作是同步执行,影响性能。

a、Read through处理流程:
app--->cache hit ------->yes----->return data
------->no------->cache read data from lower memory ---->return data

b、Write through处理流程:
app---->cache hit---->yes---->write cache ---->cache write data back to lower memory
----->no------>write data to lower memory

Write behind Caching
更新操作只更新缓存,不更新数据库,由cache异步批量同步数据库。
1、I/O操作性能优异
2、但数据更新不是强一致性,存在数据丢失风险。

在云计费系统中,比较了多个缓存更新策略,最后选用cache aside模式,主要原因是读写操作是不同模块处理,计算单元的负责私有缓存维护,其他模块无法操作计算单元的私有缓存。

在云计费多级缓存架构中,通过Cache aside模式和Cache生命期管理实现多级缓存数据一致性维护。

读操作:
app--->处理数据更新消息------>根据key查找私有缓存,如果找到则置该key为失效
------>处理话单消息------->cache hit ---->yes---->return data
---->no(未找到或者是过期、失效的key)---->从redis读取数据---->更新到私有缓存,置生命期----->返回数据

写操作:
infoload--->更新redis数据库---->查找订阅该key的topic及所属分区---->发送该key数据更新的消息

你可能感兴趣的:(多级缓存更新策略)