# Caching Strategies and How to Choose the Right One

DevFeed: [Caching Strategies and How to Choose the Right One](<https://devfeed.tech/articles/caching-strategies-and-how-to-choose-the-right-one-24981.md>)

Original publisher: [Read original article](<https://codeahoy.com/2017/08/11/caching-strategies-and-how-to-choose-the-right-one/>)

Author: umer

Published: 2017-08-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [Code Ahoy - Articles](<https://devfeed.tech/sources/code-ahoy-articles.md>)

Topics: [Caching](<https://devfeed.tech/topics/caching.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Redis](<https://devfeed.tech/topics/redis.md>), [systems](<https://devfeed.tech/topics/systems.md>)

Tags: [cache](<https://devfeed.tech/tags/cache.md>), [caching](<https://devfeed.tech/tags/caching.md>), [caching-strategies](<https://devfeed.tech/tags/caching-strategies.md>), [database](<https://devfeed.tech/tags/database.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [performance](<https://devfeed.tech/tags/performance.md>), [redis](<https://devfeed.tech/tags/redis.md>), [strategy](<https://devfeed.tech/tags/strategy.md>), [systems](<https://devfeed.tech/tags/systems.md>)

## AI overview

This tutorial explains how caching strategies should be chosen based on data access patterns, including write frequency, read frequency, and whether returned data is unique. It describes cache-aside caching, including cache hits, cache misses, database fallback, and the use of Redis and Memcached.

## Source excerpt

👉 Read First: A Brief Overview of Caching Caching is one of the easiest ways to increase system performance. Databases can be slow (yes even the NoSQL ones) and as you already know, speed is the name of the game. If done right, caches can reduce response times, decrease load on database, and save costs. There are several strategies and choosing the right one can make a big difference. Your caching strategy depends on the data and data access patterns. In other words, how the data is written and read. For example: is the system write heavy and reads less frequently? (e.g. time based logs) is data written once and read multiple times? (e.g. User Profile) is data returned always unique? (e.g. search queries) A caching strategy for Top-10 leaderboard system for mobile games will be very different than a service which aggregates and returns user profiles. Choosing the right caching strategy is the key to improving performance. Let's take a quick look at various caching strategies. Cache-Aside This is perhaps the most commonly used caching approach, at least in the projects that I worked on. The cache sits on the side and the application directly talks to both the cache and the database. There is no connection between the cache and the primary database. All operations to cache and the database are handled by the application. This is shown in the figure below. Here's what's happening: The application first checks the cache. If the data is found in cache, we've cache hit. The data is read and returned to the client. If the data is not found in cache, we've cache miss. The application has to do some extra work. It queries the database to read the data, returns it to the client and stores the data in cache so the subsequent reads for the same data results in a cache hit. Use Cases, Pros and Cons Cache-aside caches are usually general purpose and work best for read-heavy workloads. Memcached and Redis are widely used. Systems using cache-aside are resilient to cache failures.