# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbooks.ezzah.dev/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
