Loading…
Loading…
4 карточек
How does the Cache-Aside (Lazy Loading) pattern work?
нажми, чтобы перевернуть
The most popular caching pattern. Read: check cache -> cache hit -> return. Cache miss -> read DB -> write to cache -> return. Write: update DB -> invalidate cache. Lazy loading: only requested data is cached. Stale data is possible between updating the DB and invalidating the cache.
// Cache-Aside pseudo-code
async function getData(key) {
let data = await redis.get(key);
if (!data) {
data = await db.query(key);
await redis.set(key, data, 'EX', 3600);
}
return data;
}Когда да
Read-heavy workloads, data changes infrequently, tolerance for eventual consistency
Когда нет
Data changes frequently and strict consistency is required
Совет на собеседовании
This is the default pattern — if not specified otherwise, use Cache-Aside
Свайп вправо — знаю, влево — не знаю
