在 DB 和 redis 缓存之间同步数据的最佳策略是什么 [英] what is the best strategy to sync data between DB and redis cache

查看:32
本文介绍了在 DB 和 redis 缓存之间同步数据的最佳策略是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Oracle db,我们想使用Redis Cache机制,我们将一些DB数据子集添加到缓存中,当DB中的数据发生变化时是否自动与DB同步或者我们将不得不实施同步策略,如果是,最好的方法是什么.

We are using Oracle db, we would like to use Redis Cache mechanism, We add some subset of DB data to cache, does it sync with DB automatically when there is a change in the data in DB or we will have to implement the sync strategy, if yes, what is the best way to do it.

推荐答案

当数据库中的数据发生变化时是否自动与数据库同步

does it sync with DB automatically when there is a change in the data in DB

不,没有.

我们将不得不实施同步策略,如果是,最好的方法是什么.

we will have to implement the sync strategy, if yes, what is the best way to do it.

这取决于您的具体情况.通常缓存以两种常见方式同步:

This will depend on your particular case. Usually caches are sync'd in two common ways:

  1. 缓存过期的数据.一旦缓存数据过期,后台进程就会向缓存添加新数据,依此类推.通常有数据会以不同的时间间隔刷新:10 分钟、1 小时、每天...

  1. Data cached with expiration. Once cached data has expired, a background process adds fresh data to cache, and so on. Usually there's data that will be refreshed in different intervals: 10 minutes, 1 hour, every day...

按需缓存数据.当用户请求某些数据时,该请求会经过非缓存路径,该请求将结果存储在缓存中,并且后续的数量有限如果缓存可用,请求将直接读取缓存数据.这种方法在缓存失效间隔方面也可以落入#1.

Data cached on demand. When an user requests some data, that request goes through the non-cached road, and that request stores the result in cache, and a limited number of subsequent requests will read cached data directly if cache is available. This approach can fall into #1 one too in terms of cache invalidation interval.

现在我相信您有足够的细节来思考在您的特定情况下什么可能是您的最佳策略!

Now I believe that you've enough details to think about what could be your best strategy in your particular case!

这篇关于在 DB 和 redis 缓存之间同步数据的最佳策略是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆