Project cache is how to use? If you are using improper cache What are the consequences?

Copyright: ~ reproduced please marked, thank you - if infringement please private letter to me, I will immediately delete ~ https://blog.csdn.net/baidu_26954625/article/details/90648355

本系列内容转载自git项目advancejava

Face questions analysis

Project cache is how to use?

This, combined with the need to project their own business.

Why use a cache?

Caching, has two main purposes: high performance, high concurrency.

high performance

Assume such a scenario, you have an operation, a request came, Hangchihangchi you all kinds of mess operations mysql, check out half a result, time-consuming 600ms. But the results may not become the next few hours, or can be changed without immediate feedback to the user. So this time I supposed to?
Cache ah, toss the result of 600ms check out, throw cache, a key corresponding to a value, next time someone check, do not go mysql toss 600ms, and from the cache, by a key to check out a value directly, 2ms get. 300 times performance increase.
That is the result of complex operations for some time-consuming need to check out, and change back very determined, but there are a lot of read request, then check out the results directly in the cache, the cache is directly read like the back.

High concurrency

mysql database so heavy, simply did not designed to allow you to play high concurrent, although you can also play, but natural support is not good. mysql single 2000QPS started easily supported to the police.
So if you have a system, a second peak of over 10,000 requests, that a single mysql will definitely die. You can only this time on the cache, the cache put a lot of data, do not put mysql. Caching feature simple, it means key-value operation, the amount of concurrent easy one second stand-alone support tens of thousands of hundreds of thousands, support high concurrency so easy. Stand-alone carrying amount is several times the concurrent mysql stand-alone.
Cache memory is gone, it is natural memory support high concurrency.

What adverse consequences after using the cache?

Common caching questions are the following:
• cache and dual-write database inconsistencies
• Avalanche cache, the cache penetrate
• cache concurrency competition
behind again in detail.

Guess you like

Origin blog.csdn.net/baidu_26954625/article/details/90648355