开发者

PHP memcached, what's the real perk?

开发者 https://www.devze.com 2023-02-13 03:33 出处:网络
I just installed memcached and tried a couple of sample code found on php.net but since I\'m a newbie on this, i dont get the advantage of using it, where I can store the same data 开发者_Python百科in

I just installed memcached and tried a couple of sample code found on php.net but since I'm a newbie on this, i dont get the advantage of using it, where I can store the same data 开发者_Python百科in a session or cookie..

for instance I run a real estate website where users do a lot of searches / queries to mysql and lot of ajax queries

as far as i understood i can chace those queries...but what happen if the results change because someone posted a new ad? how can memcached know that?

so, question is, why should I use it and in wich occasions?

thanks!


You have to know what to cache and what not to cache. To take your example, say your site gets insanely poplar and you have a 100 million real estate listings. And you have millions of users doing searches and looking at the details. That's a lot of queries!

Enter Memcached, if you (for example) cache the detailed listing view in Memcached by saving the results of that query, you cut down the amount of load. This is because, apart from the first time where the server queried MySQL, every other hit is on Memcached.

Another thing you could do is save the results of the searches by storing the search query hash as the key. Depending on how much memory you have, that again would decrease load because Memcached is simply serving up the cached pages.

It's up to you to decide how long you're going to keep the cache as well as how your invalidation scheme would run (maybe clear the key when you add a new property, or only updates once a day).

0

精彩评论

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