用于分页的 Memcache

发布于 2024-09-28 03:31:48 字数 607 浏览 0 评论 0原文

这在实施上感觉是一个非常糟糕的主意,考虑到潜在的内存成本,我不确定是否可以节省速度。

使用 Dalli 和 Memecache 存储一组数据,这些数据在每个需要分页的页面请求上提取。它有很多数据,所以如果可能的话,我真的不想继续访问数据库,但我也不知道这个操作对于内存来说有多昂贵,无论是在内存缓存中还是在系统内存中。为了分页,我基本上执行以下操作:

  1. 调用 memcache 以查看给定数据是否存在
  2. 如果找到,则获取数据并转到 4。
  3. 如果未找到,则从数据库获取并缓存
  4. Dup 对象,因为对象已冻结。 ?? <-- 似乎是一个非常糟糕的主意...
  5. 返回分页数据进行显示。

WillPaginate 必须对来自数据库的数据集执行操作,但它会抛出“无法修改冻结”对象”错误。

这有多糟糕? dup-ing 一个大对象(它被缓存以节省调用数据库的时间)似乎最终会消耗大量额外的内存并运行 GC 比需要的更多。有人建议一些解决这个问题的方法吗?

This feels like a really bad idea on implementation and I'm not sure of the speed savings given the potential cost in memory.

Using Dalli and Memecache to store a set of data that gets pulled on every page request that needs to be paginated. Its a lot of data so I'd really rather not keep hitting the database if possible, but I also don't know how expensive this operation is for memory, both in memcache as well as just in system memory. To paginate, I do basically the following:

  1. Call to memcache to see if given data exists
  2. If found, get data and go to 4.
  3. If not found, get from database and cache
  4. Dup object because object is frozen. ?? <-- seems like a really bad idea...
  5. Return paginated data for display.

WillPaginate has to perform actions on the dataset coming out of the DB but it throws a "can't modify frozen object" error.

How much bad is this? dup-ing a large object (which is cached to save time in calls to the db) seems like it will end up chewing up a lot of extra memory and run the GC a lot more than needs be. Anyone suggest some ways around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一影成城 2024-10-05 03:31:48

您还可以缓存渲染的 html,而不是在模型/列表视图中处理对象。您甚至可以预先缓存内容以获得额外的提升:)

Instead of working with the objects at a Model / List view, you can also cache the rendered html. You can even pre-cache the contents for an extra boost :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文