缓存分页结果,清除更新-如何解决? [英] Caching paginated results, purging on update - how to solve?

查看:304
本文介绍了缓存分页结果,清除更新-如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个论坛,我们正在实现apc和内存缓存解决方案,以节省数据库一些工作.

I've created a forum, and we're implementing an apc and memcache caching solution to save the database some work.

我开始使用诸如"Categories :: getAll"之类的键来实现缓存层,如果我有用户特定的数据,则将诸如用户ID之类的键附加到键中,这样您将得到"User::getFavoriteThreads|1471".当用户添加新的收藏夹线程时,我将删除缓存键,它将重新创建条目.

I started implementing the cache layer with keys like "Categories::getAll", and if I had user-specific data, I'd append the keys with stuff like the user ID, so you'd get "User::getFavoriteThreads|1471". When a user added a new favorite thread, I'd delete the cache key, and it would recreate the entry.

但是,问题来了:

我想在论坛中缓存主题.足够简单,"Forum :: getThreads | $ iForumId".但是...通过分页,我必须将其拆分为多个缓存条目,例如

I wanted to cache the threads in a forum. Simple enough, "Forum::getThreads|$iForumId". But... With pagination, I'd have to split this into several cache entries, for example

"Forum::getThreads|$iForumId|$iLimit|$iOffset".

没关系,直到有人在论坛上发布新话题.现在,无论限制和偏移量是多少,我都必须删除"Forum::getThreads|$iForumId"下的所有键.

Which is alright, until someone posts a new thread in the forum. I will now have to delete all the keys under "Forum::getThreads|$iForumId", no matter what the limit and offset is.

什么是解决此问题的好方法?我真的不希望遍历所有可能的限制和偏移,直到发现不再匹配的东西为止.

What would be a good way of solving this problem? I'd really rather not loop through every possible limit and offset until I find something that doesn't match anymore.

谢谢.

推荐答案

您还可能希望根据工作量和CPU成本来了解存储缓存数据的成本,以及如何购买缓存你.

You might also want to have a look at the cost of storing the cache data, in terms of your effort and CPU cost, against how what the cache will buy you.

如果您发现80%的论坛视图都在主题的第一页,那么您可以决定仅缓存该页面.这意味着缓存读取和写入都更容易实现.

If you find that 80% of your forum views are looking at the first page of threads, then you could decide to cache that page only. That would mean both cache reads and writes are much simpler to implment.

与用户喜欢的线程列表相同.如果这是每个人都很少访问的内容,则缓存可能不会将性能提高太多.

Likewise with the list of a user's favourite threads. If this is something that each person visits rarely then cache might not improve performance too much.

这篇关于缓存分页结果,清除更新-如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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