LRU Cache algorithm

Source: Internet
Author: User

Introduction:

We always have a phone book all the Friends of the phone, but, if a friend often contact, those friends of the phone number of the phone book we can remember, but, if long time has not been contacted, to contact the friend again, we have to ask for the phone book, but, Searching by phone book is still time-consuming. However, what our brains can remember is certain, and we can only remember what we are most familiar with, and the long-time unfamiliar nature forgets.

In fact, the computer also used the same concept, we use the cache to store the previously read data, rather than throw it away, so that, again read, you can directly in the cache, and do not have to re-search again, so that the system's response capacity will be greatly improved. However, when we read a very large number of times, we can not put all the data that has been read in the cache, after all, memory size is certain, we generally put the most recently read in the cache (the equivalent of our recently contacted friend's name and phone in the brain). Now we're going to look at such a caching mechanism.

LRU Cache:

The LRU cache takes advantage of such an idea. LRU is the abbreviation for least recently used, which translates to "least recently used", that is, the LRU cache removes the least recently used data for the most recent data read. And the most often read, but also the most read, so, using the LRU cache, we can improve the system performance.

LRU is the least recently used page replacement algorithm (Least recently used), which is the first time to eliminate the longest unused pages!

LFU is the most infrequently used page replacement algorithm (Least frequently used), which is the least visited page in a certain period of time!

For example, the second method of the time t is 10 minutes, if the paging per minute, the main memory block is 3, if the desired page trend is 2 1 2 1 2 3 4

Note that a page break will occur when paging 4 o'clock

If the LRU algorithm, should be changed page 1 (1 pages have not been used) but according to the LFU algorithm should be changed Page 3 (10 minutes, Page 3 is used only once)

It is visible that the LRU key is to see the last time the page was used to schedule the duration of the event,

The key to Lfu is to see how often the page is used within a certain time period!

Reference: http://www.cnblogs.com/dolphin0520/p/3749259.html

LRU Cache algorithm

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.