Some questions about caching! Please, Daniel!

Source: Internet
Author: User

The pattern is now given, in the case of high concurrency, the use of caching to reduce the interaction of the database, thereby increasing the speed.

That is to read some of the usual data in the database as a cache and put it on the relevant server. The data that the user operates is dominated by the data in the cache, and the database serves only as a secondary function.

Problem:

When to cache data: (Can't answer)

What data is stored in the cache: storage of data that is not changed at a specific point in time, with high utilization

How long: Depends on the type of data, not change the frequency of or change the high

What kind of data needs to be stored in the database: (Can't answer)

When the cache interacts with the database: Use listeners in the cache framework (the conditions you specify, such as how many grams of cache are reached ...) )

Time to clean up the cache: periodically sample the data in the cache and clean up some infrequently used data

Advantages and disadvantages of using this pattern:

Pros: Less interaction with databases, faster data acquisition
Cons: Cache data loss-----------server outage increases costs by backing up cached data

The above questions, answers are self-organized, there must be shortcomings or the wrong place, there are some answers, I hope to know that Daniel can be generous enlighten! Thank you!

Comment Content:

Comment 1:

If the system is large and the database is in a bottleneck, consider caching.

about how long the cache, should be combined with business logic, some data does not change frequently, can be stored for a long time, some relatively frequent changes, can save time shorter.

And some data can not be cached, for example, user payment information, related to money, can not be cached.

If you use memcached or Redis, this caching system can periodically cache data to the file system, and even if the outage restarts, the previous cache data can be restored to some extent.

    • Comment 2: According to your own architecture for each hierarchical data, those that are relatively not constantly changing, or can allow changes to have a certain lag of data, caching, but also to provide the interface to clear the cache, according to different business to provide different cache time.
    • 1. Receive the request, query the cache first, query the disk (MySQL and other databases), query out, put the data into the cache, easy to use the next request

      2. Cache preheating, for the comparison of small changes, large query volume of data, you can start the service before the data load to the cache, called preheating

      3. For MC (memcached) Use consistent hash algorithm as far as possible, avoid MC server down, cache large area failure.

      4. Using a cache cluster, the cache is distributed across multiple servers, increasing availability

    • I did a cache, is modeled after Hibernate, is based on the SQL parsing and isolated values are stored in the cache, with the LRU algorithm, when the update occurs, the deletion of the operation, the cache is emptied. You said to save some at a specific point in time, the use of high-rate data, in fact, the expression is a level two cache, the cache also has a level and two-level distinction.

Some questions about caching! Please, Daniel!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.