Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 9 Current »

What is cache & types of caching ?

  • Caching is a mechanism to improve the performance of any type of application.

  • A cache is a software or hardware component aimed at storing data so that future requests for the same data can be served faster.

FORMS OF CACHING

DESCRIPTION

In-Memory Caching

Cached data is stored directly in RAM. The most common implementation of this type of caching is based on key-value databases.

Database Caching

Each database usually comes with some level of caching. Specifically, an internal cache is generally used to avoid querying a database excessively. Although each database can implement this differently, the most popular approach is based on using a hash table storing key-value pairs.

Web Caching

Web Client Caching : it is also called Web Browser Caching. It works in a very intuitive way. The first time a browser loads a web page, it stores the page resources, such as text, images, stylesheets, scripts, and media files.

Web Server Caching : storing resources server-side for reuse. Such an approach is helpful when dealing with dynamically generated content, which takes time to be created : avoids servers from getting overloaded, reducing the work to be done, and improves the page delivery speed.

CDN caching

It is aimed at caching content, such as web pages, stylesheets, scripts, and media files, in proxy servers. It can be seen as a system of gateways between the user and the origin server, storing its resources. When the user requires a resource, a proxy server intercepts it and checks to see if it has a copy.

What is a caching strategy ?

It’s to determine the relationship between data source and your caching system, and how your data can be accessed.

What are the 3 types of cache memory ?

Cache is graded as Level 1 (L1), Level 2 (L2) and Level 3 (L3):

  • L1 is usually part of the CPU chip itself and is both the smallest and the fastest to access. Its size is often restricted to between 8 KB and 64 KB.

  • L2 and L3 caches are bigger than L1. They are extra caches built between the CPU and the RAM. Sometimes L2 is built into the CPU with L1. L2 and L3 caches take slightly longer to access than L1. The more L2 and L3 memory available, the faster a computer can run.

Not a lot of physical space is allocated for cache. There is more space for RAM, which is usually larger and less expensive.

A diagram of the architecture and data flow of a typical cache memory unit : https://www.techtarget.com/searchstorage/definition/cache-memory

Why cache is faster than Database ?

https://alonge.medium.com/why-cache-storage-is-80times-faster-than-disk-storage-hdds-b1e9fef5fd8d :

Caches : are in-memory data stores that maintain/provide fast access to data. The latency of in-memory stores is designed to be submillisecond making them the fastest data store after SSDs

  • Reading 4KB randomly from an SSD takes 150 microseconds

  • Reading 1MB sequentially from cache memory takes 250 microseconds

  • Reading 1MB sequentially from an SSD takes 1,000 microseconds or 1 millisecond

  • Reading 1MB sequentially from disk (HDDs) takes 20,000 microseconds or 20 milliseconds.

What is the purpose of caching ?

A cache's primary purpose is to increase data retrieval performance by reducing the need to access the underlying slower storage layer. Trading off capacity for speed, a cache typically stores a subset of data transiently, in contrast to databases whose data is usually complete and durable.

How does caching work in microservices ?

What is Distributed Cache ?

A system that pools together the random-access memory (RAM) of multiple networked computers into a single in-memory data store used as a data cache to provide fast access to data. While most caches are traditionally in one physical server or hardware component, a distributed cache can grow beyond the memory limits of a single computer by linking together multiple computers–referred to as a distributed architecture or a distributed cluster–for larger capacity and increased processing power.

Useful in environments with high data volume and load.

A distributed cache pools the RAM of multiple computers into a single in-memory data store used as a data cache to provide fast access to data.

  • No labels