Rails ruby-china 是否已读用 rails cache 能存多少?

siyang1982 · February 28, 2012 · Last by huacnlee replied at February 28, 2012 · 2970 hits

学习了一下 ruby-china 的未读标记,user.rb, 是将已读内容及用户 ID 组成 key 放在 cache 里。

def topic_read?(topic)
    # 用 last_reply_id 作为 cache key ,以便不热门的数据自动被 Memcached 挤掉
    last_reply_id = topic.last_reply_id || -1
    Rails.cache.read("user:#{self.id}:topic_read:#{topic.id}") == last_reply_id
end

想请教一下这种方式最多能保存多少,感觉会造成老帖全都变成未读?

这个放在 Memcached 里面,设计的核心点是 用户用到的其实也就前面几页的,而其他历史的会由于长久没有用到,会随着时间的推移被 Memcached 里面其他的 cache 给挤掉,所以不用担心能存多少。

You need to Sign in before reply, if you don't have an account, please Sign up first.