Cache-aside

Last updated

What is Cache-aside?

The application is responsible for reading and writing from storage. The cache does not interact with storage directly. The application does the following:

  • Look for entry in cache, resulting in a cache miss

  • Load entry from the database

  • Add entry to cache

  • Return entry

    def get_user(self, user_id): user = cache.get("user.{0}", user_id) if user is None: user = db.query("SELECT * FROM users WHERE user_id = {0}", user_id) if user is not None: key = "user.{0}".format(user_id) cache.set(key, json.dumps(user)) return user

Memcached is generally used in this manner. Subsequent reads of data added to cache are fast. Cache-aside is also referred to as lazy loading. Only the requested data is cached, which avoids filling up the cache with data that isn't requested.

Cache Aside

Free resources to learn Cache-aside

More in stage 14: Asynchronism

Cache-aside: common questions

Can I learn Cache-aside in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Cache-aside in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this Cache-aside tutorial for beginners?

It is lesson 52 of 147 in the free System Design roadmap, in stage 14, Asynchronism. If you are new to System Design, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me