Rails 计数器缓存与计算 [英] Rails counter cache vs calculation

查看:40
本文介绍了Rails 计数器缓存与计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要显示总计的集合,我的想法是为我需要的每个总计使用缓存.但是,我还需要深入研究数据集.所以很可能无论如何我都必须加载集合.那么我应该继续使用缓存还是只使用计算?

I have a collection which I want to show totals for, and the idea was to use a cache for each of the totals I need. However I also will need to drill down into the data set. So most likely I will have to load the collection anyway. So should I still use the cache or just use a calculation?

推荐答案

答案取决于集合的大小.如果集合非常大(1000 个或项目),那么缓存可能是一个好主意.如果它只有少数并且您在表上有索引以快速找到相关行,那么可能不需要缓存,尤其是如果您无论如何都必须钻取到集合中.

The answer depends on the size of the collection. If the collection is very large (1000's or items), then caching is probably a good idea. If its only a handful and you have indexes on the tables to quickly find the relevant rows, then a cache is probably not required, especially if you have to drill into the collection anyway.

与所有此类问题一样,正确答案通常是视情况而定".这在很大程度上取决于您的要求和数据等.

As with all these sort of questions, the correct answer is usually 'it depends'. It very much depends on your requirements and data etc.

这篇关于Rails 计数器缓存与计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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