我阅读了官方指南。它说有页面缓存
、 Action 缓存
和片段缓存
,但它们不是我想要的。
我只是喜欢缓存一个对象,而不是整个页面或 View 片段,就像这样的伪代码:
def show
cache @ads, :expires_in => 1.hour do
@ads = Advertisement.all
do
end
这可能吗?使用 memcache
还是 redis
?
最佳答案
试试这个:
#To cache the object
Rails.cache.write('cache-key', object)
#Load the object from the cache
Rails.cache.read('cache-key')
关于ruby-on-rails - 如何在 Rails 中缓存任意对象(基于时间)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8236637/