Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What is caching? And why does it hate me?

What is caching? And why does it hate me?

Addam Hardy

July 03, 2019
Tweet

More Decks by Addam Hardy

Other Decks in Technology

Transcript

  1. cache, noun, \’kash\ In computing, a cache is a high-speed

    data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data’s primary storage location. Caching allows you to efficiently reuse previously retrieved or computed data.
  2. Basically, it’s just an address book of pre- calculated data.

    A value is stored under a key (jargon alert: key/val store) so that it can be quickly referenced later.
  3. Key Value username jessica 64 x 16 1024 124^12 1.3124788

    price $52.65 Basically, it’s just an address book of pre- calculated data. A value is stored under a key (jargon alert: key/val store) so that it can be quickly referenced later.
  4. TYPICAL CACHING SOURCES IN WEB APPLICATIONS ▸ Browser cache ▸

    Web server cache CACHING: TYPICAL WEB APPLICATION CACHING
  5. TYPICAL CACHING SOURCES IN WEB APPLICATIONS ▸ Browser cache ▸

    Web server cache THAT’S IT RIGHT? CACHING: TYPICAL WEB APPLICATION CACHING
  6. TYPICAL CACHING SOURCES IN WEB APPLICATIONS ▸ Browser cache ▸

    Web server cache THAT’S IT RIGHT? NOT EVEN CLOSE CACHING: TYPICAL WEB APPLICATION CACHING
  7. TYPICAL CACHING SOURCES IN WEB APPLICATIONS ▸ DNS Cache (on

    user’s computer) ▸ Browser assets cache (on user’s computer) ▸ Browser network requests cache (on user’s computer) ▸ DNS cache (on DNS server) ▸ Web server requests cache (on website’s server) ▸ Database records cache in web application (on website’s server) ▸ Database query cache in database (on website’s database server) ▸ CDN cache (on website’s CDN server) CACHING: TYPICAL WEB APPLICATION CACHING
  8. THERE ARE ONLY TWO HARD THINGS IN COMPUTER SCIENCE: CACHE

    INVALIDATION AND NAMING THINGS. - PHIL KARLTON
  9. CACHING: WHY IS IT HARD? THE TRUTH IS NO LONGER

    THE TRUTH ▸ Responses (answers) you get to queries (for questions) now may or may not be the truth. ▸ Reproducing behavior with truth variability is hard. Reproducing behavior with 15 layers of truth variability, exponentially so.
  10. CACHING: WHY IS IT HARD? THE TRUTH IS NO LONGER

    THE TRUTH ▸ Responses (answers) you get to queries (for questions) now may or may not be the truth. ▸ Reproducing behavior with truth variability is hard. Reproducing behavior with 15 layers of truth variability, exponentially so. HOW DO WE GET AROUND THIS?
  11. CACHING: INVALIDATION INVALIDATION == REMOVE LAST KNOWN VALUE AND GET

    NEW VALUE When we “invalidate” the cache, we tell the system that is storing the value, that it needs to forget what it knows now, and get a new value to store.
  12. CACHING: INVALIDATION most of the time, cached values have a

    set expiration date and time. When this set time is reached, the cached value is automagically deleted. CACHE INVALIDATION BY EXPIRATION
  13. CACHING: INVALIDATION This is what happens when you “hard refresh”

    your browser. (⌘ (command) + ⇧(shift) + R) YOU CAN FORCE A INVALIDATION BEFORE THE CACHE EXPIRATION DATETIME [ ]
  14. CACHING: INVALIDATION This is what happens when you “hard refresh”

    your browser. (⌘ (command) + ⇧(shift) + R) YOU CAN FORCE A INVALIDATION BEFORE THE CACHE EXPIRATION DATETIME [ ] WHY DOESN’T THIS SOLVE ALL OF MY PROBLEMS THEN?
  15. CACHING: INVALIDATION WHY DOESN’T THIS SOLVE ALL OF MY PROBLEMS

    THEN? because this is only invalidating your browser cache. it’s not invalidating all other layers of caching.
  16. A HARD REFRESH ONLY INVALIDATES YOUR BROWSER CACHES. OFTEN IT

    WILL COVER YOUR NEEDS, BUT IT’S IMPORTANT TO KNOW THERE’S MANY OTHER FACTORS INVOLVED.