使用 memcacheD 进行缓存的初学者指南

发布于 2024-11-03 08:03:44 字数 1536 浏览 0 评论 0原文

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

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

发布评论

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

评论(1

战皆罪 2024-11-10 08:03:44

但是我到底应该做什么
缓存?

您应该缓存不经常更改且被多次读取的数据。例如,我们以一个论坛为例 - 您可以缓存论坛的初始页面,其中显示可用的论坛、论坛描述和论坛 ID,以便您可以查看各种论坛类别下的主题。

由于您不可能每秒创建、删除或更新论坛,因此可以安全地假设读:写比率有利于读取,这允许您缓存显示论坛的首页,通过这样做,您可以减轻数据库的负载,因为大多数访问您的网站时都不需要访问它。

您还可以更进一步地进行缓存 - 缓存站点提供的所有内容,并将缓存过期时间设置为 5 分钟。假设您的数据库并不大(数百 GB)并且适合可用 RAM - 您将有效地每 5 分钟查询一次数据库。
假设您每天有大量访问(假设有 20,000 次独立访问) - 您可以计算在连接到数据库和提取数据时节省了多少资源。

but what exactly am I suppose to
cache?

You're supposed to cache the data that doesn't change often and is read many times. For example, let's take a forum - you'd cache the initial page of the forum that displays forums available, forum description and forum IDs that allow you to see topics under various forum categories.

Since it's not likely that you create, delete or update forums every second, it's safe to assume that the read:write ratio is in favor of read which allows you to cache that front page where you display forums and by doing so, you are alleviating the load on your database since it doesn't have to be accessed for most visits to your site.

You can also take this caching one step further - you cache everything your site has to offer and you set your cache expiry time to 5 minutes. Assuming your database isn't huge (hundreds of gigabytes) and that it fits available RAM - you'd effectively query your database every 5 minutes.
Assuming you have a lot of visits per day (let's say 20 000 unique visits) - you can calculate how much it attributes to saving resources when connecting to database and extracting data.

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