> For the complete documentation index, see [llms.txt](https://gitbooks.ezzah.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbooks.ezzah.dev/master.md).

# ElastiCache Strategies

## Two Caching Implementation Strategies

* Lazy Loading / Cache-Aside / Lazy Population
* WriteThrough

## Lazy-Loading

![](/files/-MVvFoUuTm_nvjCqpqzi)

Pros:

* Only requested data is cached; no useless data&#x20;
* Node failures are not fatal (just increased latency to warm cache)

Cons:

* Cache miss penalty will result in 3 round trips, noticeable delay in initial request
* Stale data: data can be updated in database and outdated in the cache

## WriteThrough

![](/files/-MVvG5yAvXmjDNxHtyfu)

Pros:

* Data in dcache is never stale, reads are quick
* Write penalty instead of ready penalty (each write requires 2 calls)

Cons:

* Missing Data until it is added/updated in the DB. **Mitigation** is to implement **Lazy-Loading** strategy in conjunction&#x20;
* **Cache churn** - a lot of the data will never be read into the cache&#x20;

## Managing Cache with Cache Evictions and Time-To-Live (TTL)

Eviction can occur in three ways:

1. Delete item explicitly in the cache
2. Item evicted due to full memory and not been recently used (LRU)
3. Set item time-to-live (TTL)

TTL can range from a few seconds to hours and days.
