开发者

A beginners guide to caching using memcacheD [closed]

开发者 https://www.devze.com 2023-02-28 16:49 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. 开发者_开发百科

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 9 years ago.

Improve this question

There are a lot of tutorial on the Internet which claim to teach you how to use memcacheD, but most of them are about memcache (hence the emphasis on the d).

In php, memcached doesn't even have a connect method. Also a lot of these tutorial just teach you how to connect and add values, but I can figure that out by reading the manual, so please help me to create a one stop reference for memcached. What strategies would you recommend, what are the best practices? How would you cache something like a forum, or a social site with ever-changing data?

The trouble I seem to have is, I know how to connect, add and remove values, but what exactly am I suppose to cache? (I'm just experimenting, this is not for a project, so I can't really give an example).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消