{ // cached data available return get_article_from_cache(id) // fast! } else { // cached data unavailable, // retrieve from network and put to cache article = get_article_from_rest_api(id) // slow! save_article_to_cache(id, article) return article } }
lifespan of your cached data, invalidate (i.e. throw it away) at the right time! • Invalidation triggers:! – Data’s timespan limit! – Memory/Disk space limit! – User actions (e.g. manual refresh)! – Periodic invalidation! – Push notification! • Which data to invalidate when we reached the limit?! – LRU (Least Recently Used)! – LFU (Least Frequently Used)! – MRU (Most Recently Used)! – Bélády's Algorithm!
remote bitmap! – Cache expensive calculation results that don’t change too often! • Avoid:! – Cache sensitive data that might affect users’ perception if they see the cached one (e.g. bank balance)!