What is caching and how does it work?

Tram Ho

What is caching?

Caching is a technique to increase data access and reduce the load for the system. The cache is a collection of data, often temporary, allowing the reuse of previously captured or calculated data to accelerate data retrieval later.

How does caching work?

Data in cache (buffer) is usually stored in RAM (Random-access memory). The main purpose of cache is to increase data retrieval performance. Cache usually stores a temporary subset of data.

RAM and In-Memory Engines

Due to high request speed or IOPS (Input / Output operations per second) supported by RAM and In-Memory engines , cache helps improve data retrieval performance and reduce scale costs. To scale with traditional database systems and hardware, a lot of resources are required. And this can cost you money and still not be able to achieve fast performance (less latency when retrieving data) like using In-Memory cache.

Applications:

Cache can be applied and deployed in different layers including: Operating Systems, Networking containing Content Delivery Networks (CDN) and DNS, web applications, and Databases. Using the cache significantly reduces latency and improves IOPS for heavily workloaded applications such as Q&A portals, gaming, sharing media, and social networks. The information stored in the cache can be the results of database queries, API requests / responses and HTML, JavaScript, and image files of web pages. Calculating workloads that work with data sets, such as high performance calculations, will also benefit from the same In-Memory data layer as the cache. In these applications, very large data sets must be accessed in real time on scanners with hundreds of nodes. Due to the slow speed of the hardware, manipulating data in the disk-based store is a very important factor for these applications.

Design Patterns

In a distributed computing environment (DCE), caching allows systems and applications to run independently and without affecting the cache. The cache acts as an intermediary layer that can be accessed from different systems with its own life cycle topology and structure. This is particularly relevant for nodes that can automatically scale in a system. If the cache is on the same node as the application or system using it, scaling can affect cache integrity. When local caches are used, they are only useful for local application to access data. In a distributed computing environment, data can be used on many cache servers and stored in a central location because it will be useful to all places that use that data.

Caching Best Practices

When implementing a cache class, it is important to understand the validity of the cached data. The successful cache results in a high validation rate, which means the data already exists before being fetched. Cache error occurs when data fetched is not in the cache. Controls such as TTLs (Time to live) can set the survival time for the corresponding data. Whether the cache environment needs to be highly available or not, this can be satisfied by In-Memory engines like Redis. In some cases, the In-memory layer can be used as an independent data storage layer, as opposed to data stored in a primary location. In this section, it is important to determine the RTO (Recovery Time Objective) – the time it takes to recover from downtime, and the RPO (Recovery Point Objective) – the last point or transaction recorded during the process. restore, data in In-Memory engine to determine if it is appropriate or not. The design and characteristics of different In-Memory engines can be applied to meet most RTO and RPO requirements.

LayerClient-SideDNSThe webAppDatabase
Use CaseIncrease the speed of retrieving web content from web pages (browser or device)Domain name resolution to IPSpeed ​​up retrieving web content from web / app servers. Manage web sessions (server side)Increase application performance and data accessReduce latency when querying for databases
TechnologiesHTTP Cache Headers, BrowsersDNS ServersHTTP Cache Headers, CDNs, Reverse Proxies, Web Accelerators, Key / Value StoresKey / Value data stores, Local cachesDatabase buffers, Key / Value data stores
SolutionsBrowser specificAmazon Route 53Amazon CloudFront , ElastiCache for Redis , ElastiCache for Memcached , Partner SolutionsApplication Frameworks, ElastiCache for Redis , ElastiCache for Memcached , Partner SolutionsElastiCache for Redis , ElastiCache for Memcached

Caching with Amazon ElastiCache

Amazon ElastiCache is a web service that makes it easier to deploy, operate, and expand data stored in In-memory or clond cache. This service improves the performance of web applications by allowing you to retrieve information from in-memory data stores faster, instead of relying solely on disk-based databases.

Benefits of caching

  • Improve the performance of the application
  • Reduce costs for database setup
  • Improved when processing time spike during application usage
  • Reduce the load for the backend
  • Increase throughput (IOPS)
Share the news now

Source : Viblo