Web and Mobile Development - Cache

Activity Goals

The goals of this activity are:
  1. To explain the benefit and risk of using a cache
  2. 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

HTTP HEAD Example

Questions

  1. 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?
  2. 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?
  3. What kind of data structure would you use to save values into the cache?
  4. 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

  1. What data structure do you think underlies node-cache?

Submission

I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.