我有一个 Ruby on Rails 应用程序,其中使用了片段缓存并使用 memcached 来存储数据。我还有一个清扫器,它在对模型进行更改时使缓存过期。
index.html.erb
<% cache 'recent_albums' do %>
contents to be cached
<%end %>
class AlbumsSweeper < ActionController::Caching::Sweeper
observe Album
def after_save(album)
expire_cache(album)
end
def after_destroy(album)
expire_cache(album)
end
def expire_cache(album)
expire_fragment 'recent_albums'
end
end
我有一个要求,在用户点击相册页面之前,过期的片段需要用新数据刷新。有人可以帮助如何实现片段缓存数据刷新吗?