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

What is the difference between Cach...

Câu trả lời

Cache replacement and cache invalidation are two distinct concepts in caching systems, each serving different purposes to manage the data stored in a cache.

Cache Replacement

Cache replacement refers to the process of deciding which data to remove from the cache when the cache is full and new data needs to be added. Since caches have limited storage capacity, it is essential to have a strategy for evicting old or less useful data to make room for new data. Common cache replacement policies include:

  • Least Recently Used (LRU): This policy evicts the data that has not been accessed for the longest time. The assumption is that data not used recently is less likely to be used again soon[1][4].
  • Least Frequently Used (LFU): This policy removes the data that has been accessed the fewest number of times. The idea is that data accessed less frequently is less likely to be needed in the future[1][4].
  • First-In, First-Out (FIFO): This policy evicts the oldest data first, based on the order of their arrival in the cache[4][10].
  • Random Replacement: This policy randomly selects data to evict, which can be useful in certain scenarios where other strategies do not fit well[4][7].
  • Optimal Replacement (Bélády's Algorithm): This theoretical policy evicts the data that will not be used for the longest time in the future. While optimal, it is impractical because it requires future knowledge[7].

Cache Invalidation

Cache invalidation, on the other hand, is the process of removing or updating data in the cache when it becomes outdated or no longer valid. This ensures that the cache contains only fresh and accurate data, maintaining consistency with the original data source. Common cache invalidation strategies include:

  • Time-to-Live (TTL) Expiration: Data is invalidated after a specified period, ensuring that stale data is removed automatically after a certain time[1][3][13].
  • Write-through: Data is written to both the cache and the underlying storage simultaneously, ensuring consistency but with higher write latency[3][16].
  • Write-around: Data is written directly to the storage, bypassing the cache, which can reduce cache pollution but may lead to more cache misses[3][18].
  • Write-back (Lazy Write): Data is written to the cache first and later...
senior

senior

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

middle

What are some alternatives to Cache Invalidation?

middle

Name some Cache Invalidation methods

senior

Compare caching at Business Layer vs Caching at Data Laye

Bình luận

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

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