search

Home  >  Q&A  >  body text

如何实现 Redis 多级缓存的更新?

分布式开发中,使用 Redis 做二级缓存,本地静态对象做一级缓存,如何实现二级缓存被更新时通知一级缓存?

怪我咯怪我咯2780 days ago936

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-22 08:58:32

    I have not used distributed ones in actual development. Let’s discuss it with you.
    My thoughts are:

    1. Use redis Pub/Sub method to subscribe to the updates of the secondary cache. When a machine updates the cache, then Pub 一个Key,通知所有的客户端,客户端前往更新,刷新一级缓存。key的值可以按 机器号:数据key,这样搞,通过机器号判断让更新者不要更新,其它机器更新,数据keyupdate the specified data.
    2. Consider whether the first-level cache is really needed. Will not using the first-level cache cause any problems? If it is a performance issue that can be ignored, I tend to use redis directly as the first-level cache, saving time, effort and complexity :)

    reply
    0
  • PHP中文网

    PHP中文网2017-04-22 08:58:32

    The background scheduled task synchronizes the redis cache to the memory cache

    reply
    0
  • Cancelreply