使用写入时缓存扩展 Rails
我目前有一个使用传统缓存的 Rails 应用程序。 cache do
块用于缓存缓慢渲染的部分。这在大多数情况下都非常有效,除了少数页面在第一次阅读时需要很长时间才能呈现。
我想通过在底层数据发生变化时在模型或扫描器中进行渲染,将这些部分的渲染从读取端移至写入端。优选地,这将在已经使高速缓存键无效的清除器中。这是一个好方法吗?有没有“正确”的方法来做到这一点?
I currently have a rails app that uses the traditional caching. cache do
blocks are used to cache slow-rendering partials. This works great for the most part, except for a few pages which take too long to render on the first read.
I'd like to move the rendering of these partials to the write-side from the read-side, by rendering in either the model or in sweepers when the underlying data changes. Preferably, this would be in the sweepers that already invalidate the cache keys. Is this a good approach? Is there a "right" way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是需要一段时间才能呈现的实际部分还是实际获取数据所需的查询?如果是后者,您最好以直写方式缓存这些内容,这可能比尝试在写入时更新缓存的部分更简单。
Is it the actual partial that is taking a while to render or the queries required to actually get the data? If it's the latter you're better off caching those in a write-through manner, it might be simpler than trying to update cached partials on write.