7 Use case: LRU Cache

 

This chapter covers

  • Solving a problem: avoid computing things twice
  • Introducing caching as a solution
  • Describing different types of caches
  • Designing an efficient solution for LRU cache
  • Discussing MFU and other choices to handle priority
  • Discussing caching strategies
  • Reasoning about concurrency and synchronization
  • Describing how caches can be applied in a sentiment analyzer’s pipeline

This chapter is going to be different with respect to what you have seen so far in this book. We are not going to introduce a new data structure, but instead we will use the ones described in chapters 2 to 5 to create a more complex data structure; by using lists, queues, hash tables etc… as building blocks, we will be able to create an advanced data structure that can be used to quickly access values/computed results that were recently accessed – although one could argue that a cache is more than just a data structure, it’s already a sophisticated component with several moving parts: in its simplest form, it can just be implemented as an associative array, but we will see during the course of this chapter that it can become as complex as a web service.

In this chapter we are going to delve into the details of how caches of increasing complexity work, so that, after reading it, you should be able to articulate an informed opinion on whether the topic.

7.1            Don’t Compute Things Twice

 
 

7.2            First Attempt: Remembering Values

 
 
 
 

7.2.1                     Description and API

 
 
 

7.2.2                     Fresh Data, Please

 
 
 
 

7.2.3                     Handling Asynchronous Calls

 
 

7.2.4                     Marking Cache Values as “Loading”

 
 
 

7.3            Memory Is Not Enough (Literally)

 

7.4            Getting Rid of Stale Data: LRU cache

 
 
 
 

7.4.1                     Sometimes you have to double down on problems

 

7.4.2                     Temporal Ordering

 
 

7.4.3                     Performance

 
 
 

7.5            When Fresher Data Is More Valuable: LFU

 
 
 

7.5.1                     So How Do We Choose?

 
 
 

7.5.2                     What Makes LFU Different

 
 
 

7.5.3                     Performance

 
 

7.5.4                     Problems With LFU

 
 
 

7.6            How to Use cache is Just as Important

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest