Câu hỏi phỏng vấn Caching
Câu hỏi

What are Cache Replacement (o...

Câu trả lời

Cache replacement (or eviction) policies are algorithms used to manage the contents of a cache when it reaches its capacity. These policies determine which data should be removed to make room for new data, aiming to optimize the cache's performance by retaining the most relevant and frequently accessed information. Here are some of the most common cache replacement policies:

Least Recently Used (LRU)

The LRU policy evicts the item that has not been accessed for the longest period of time. The assumption is that items that haven't been used recently are less likely to be used in the near future. This policy maintains a record of the order in which items are accessed and evicts the least recently used item when the cache is full[1][3][5].

Least Frequently Used (LFU)

The LFU policy evicts the item that has been accessed the least number of times. It keeps a counter for each item to track the frequency of accesses. When the cache is full, the item with the lowest access count is removed. This policy is useful for retaining the most popular items in the cache[1][3][5].

First-In-First-Out (FIFO)

The FIFO policy evicts the oldest item in the cache, regardless of how often or recently it has been accessed. This policy treats the cache as a queue, where the first item added is the first to be removed[1][3][5].

Random Replacement (RR)

The Random Replacement policy evicts a randomly chosen item from the cache. This policy is simple to implement and has low overhead, but it may lead to suboptimal performance compared to more sophisticated policies[1][3][5].

Most Recently Used (MRU)

The MRU policy evicts the most recently accessed item. This policy is less common and is typically used in specific scenarios where the most recently used items are less likely to be accessed again soon[13].

Time-To-Live (TTL)

The TTL policy evicts items that have exceeded a predefined duration in the cache. Each item is assigned a timestamp when it is added, and items are removed once their TTL expires. This policy is useful for applications with time-sensitive data[10].

Optimal Replacement (Bélády's Algorithm)

T...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

What are some alternatives to Cache Invalidation?

junior

What is Cache Invalidation?

junior

Is Redis just a cache?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào