Web and Mobile Development - Cache
Activity Goals
The goals of this activity are:- To explain the benefit and risk of using a cache
- To use the HEAD verb to check the modified date on an item for refreshing
The Activity
Directions
Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.Model 1: Checking Modification Date Using the HEAD verb
Questions
- How is this less expensive than making a full GET request, when we still need to do that anyway if the modification date from the HEAD response is newer than the version we have?
- In addition to the response data (such as the web page), what other information would you need to store for the cache to be effective?
- What kind of data structure would you use to save values into the cache?
- How often should you refresh the cache?
Model 2: Internal Caches with node-cache
Review this tutorial that uses
node-cache
to return data from a cache lookup, calling a function to insert into the cache only if the data is out of date or nonexistent.
Questions
- What data structure do you think underlies
node-cache
?