# Cache

* A good overview can be found [here](https://aws.amazon.com/caching/).
* Used in managing state of stateless application, reduce load off of databases for read intensive workloads etc.

## Caching Strategies

* Some common strategy based on operation done on the system can be found [here](https://blog.bytebytego.com/p/top-caching-strategies).
* Most popular strategies are,
  * Lazy Loading/Cache Aside/Lazy Population
  * Write Through

## Elasti Cache

### Icon

![Elasti Cache Icon](https://icon.icepanel.io/AWS/svg/Database/ElastiCache.svg)

### About

* Caches are in-memory databases with high performance and low latency.
* Being a managed service following tasks are managed by AWS,
  * OS maintenance/patching
  * Optimizations
  * Setup
  * Configuration
  * Monitoring
  * Failure recovery and backups
* Offers managed `Redis` or `Memcached` variants.
* For redis in cluster mode, **there can be upto 5 read replicas**.

#### Cache evictions

* Cache eviction can occur in 3 ways
  * Delete the item explicitly in the cache
  * Item is evicted because the memory is full and is not recently used.
  * You set an item's time-to-live, where in TTL can vary from a few second to hours or days.
* If too many evictions happen due to memory, you should scale up or out.

### Security

* Encryption at rest and transit is available to make sure data is secure.

## References

* [Types of caching](https://aws.amazon.com/caching/#popover-types-trigger)
* [Best Caching practices](https://aws.amazon.com/caching/best-practices/)
