Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
您应该缓存不经常更改且被多次读取的数据。例如,我们以一个论坛为例 - 您可以缓存论坛的初始页面,其中显示可用的论坛、论坛描述和论坛 ID,以便您可以查看各种论坛类别下的主题。
由于您不可能每秒创建、删除或更新论坛,因此可以安全地假设读:写比率有利于读取,这允许您缓存显示论坛的首页,通过这样做,您可以减轻数据库的负载,因为大多数访问您的网站时都不需要访问它。
您还可以更进一步地进行缓存 - 缓存站点提供的所有内容,并将缓存过期时间设置为 5 分钟。假设您的数据库并不大(数百 GB)并且适合可用 RAM - 您将有效地每 5 分钟查询一次数据库。
假设您每天有大量访问(假设有 20,000 次独立访问) - 您可以计算在连接到数据库和提取数据时节省了多少资源。
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.