💼 As a developer, you want to understand caching and incorporate it into your projects whenever possible.
This is a thread 🧵about caching.
⬇️
You want to keep often-used data in a place where you can access it much faster than its source.
For example, instead of downloading data from the server over and over again, you can store it in memory and access it from there.
👇
There are multiple strategies to accomplish this. Each one makes a different decision about which items to remove and which to keep.
👇
▫️First-in, first-out (FIFO): Evicts the oldest entry
▫️Last-in, first-out (LIFO): Evicts the newest entry
▫️Least Recently Used (LRU): Evicts the least recently used entry
👇
▫️Random replacement (RR): Evicts a random entry
▫️Least-frequently used (LFU): Evicts the entry that has been used the least
👇
▫️Time aware least recently used (TLRU): Combines LRU with expiration for each entry
👇
For example: if you are going to expire entries after a certain time, how much time is adequate? What happens if the content is updated before?
A lot of creativity needed here!
👇
There are only two hard things in Computer Science: cache invalidation and naming things. — Phil Karlton
So yeah, getting caching right is not easy.
But it’s well worth it!
👇
* functors.lru_cache decorator
* cachetools library
* Beaker library
JavaScript developers, what libraries do you use to cache stuff?