CHAPTER 8 Ensuring Correct Use of the Memoization Pattern

WHAT’S IN THIS CHAPTER?            

  • Applying the Memoization Pattern to solve business problems
  • Unit-testing implementations of the Memoization Pattern
  • Unit-testing and generically implementing the Memoization Pattern as an aspect

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at www.wrox.com/go/reliablejavascript on the Download Code tab and in the Chapter 8 download.

The organizers of the JavaScript conference are pleased with the restaurant search functionality that you and Charlotte have baked into the website, except for one thing: It’s costing them quite a bit of money. A third-party API retrieves the restaurants charges for each and every request made to it, and quite a bill was racked up just during development and testing.

The organizers have come to you and Charlotte to see if there’s anything that can be done to reduce the damage to their credit card bill once the hungry conference attendees start using the feature.

“Many attendees will probably search for the same type of cuisine,” posits Charlotte, “so we could save the results the first time any user searches for a cuisine, and return those results to the next user that searches for the same cuisine. It’s unlikely that new restaurants will open up—or existing restaurants close down—during the conference, so the API will just return the same restaurants for each type of cuisine anyway.”

While the solution ...

Get Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.