In computing, a cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data’s primary storage location. Caching allows you to efficiently reuse previously retrieved or computed data.
The data in a cache is generally stored in fast access hardware such as RAM (Random-access memory) and may also be used in correlation with a software component.
A cache's primary purpose is to increase data retrieval performance by reducing the need to access the underlying slower storage layer.
What Should You Cache?
Data that requires an slow and expensive query to acquire.
Relatively static and frequently accessed data.
Information that can be stale for an extended period.
Benefits of caching
Improved application speed
Reduced resource burden of time-consuming database queries
Reduced response latency
Caching Types:
Client Caching: With client-side caching, data is typically stored in a browser rather than making repeated queries to a web server. HTTP cache headers provide the details on how long the browser can fulfill future responses from the cache for the stored web content.
Server Caching: With server-side caching, various web caching techniques can be used to improve the performance of a website by providing caching in between the data's source and the client.
Caching Types:
Amazon's global content delivery network (CDN)
Accelerates delivery of your websites, APIs, video content, or other web assets
Integrates with other AWS products
Pay-per-use, with no long-term commitments or minimum fees required
Offers a multi-tier cache by default
Uses regional edge caches to improve latency and lower the load on your origin servers
Provides an additional layer of security for your architectures
Supports real-time, bidirectional communication over the WebSocket protocol
Deploy
You specify an origin server, like an Amazon S3 bucket or your own HTTP server, from which CloudFront gets your files. These will be distributed from CloudFront edge locations all over the world. Your HTTP server can run on an Amazon EC2 instance or on servers you manage on premises.
You create a CloudFront distribution, which tells CloudFront which origin servers to get your files from when users request the files through your web site or application. At the same time, you specify details such as whether you want CloudFront to log all requests and whether you want the distribution to be enabled as soon as it's created.
CloudFront assigns a domain name to your new distribution.
CloudFront sends your distribution's configuration, but not the content, to all of its edge locations. Edge locations are collections of servers in geographically dispersed data centers where CloudFront caches copies of your objects.
Three ways to expire content
Time to Live: If you set the TTL for a particular origin to 0, CloudFront will still cache the content from that origin. CloudFront will then make a GET request with an If-Modified-Since header, which gives the origin a chance to signal that CloudFront can continue to use the cached content if it hasn't changed at the origin.
Change Object Name: The second way requires more effort but is immediate (some CMS systems support this). Although you can update existing objects in a CloudFront distribution and use the same object names, it is not recommended. CloudFront distributes objects to edge locations only when the objects are requested, not when you put new or updated objects in your origin. If you update an existing object in your origin with a newer version that has the same name, an edge location won’t get that new version from your origin until both of the listed events occur.
Invalidate the Object: The third method should only be used sparingly for individual objects: it is a bad solution (the system must forcibly interact with all edge locations).
Web service used to deploy, operate, and scale an in-memory cache in the cloud
Improves the performance of web apps by allowing you to retrieve information from fast, managed, in-memory data stores, instead of relying on slower disk-based databases
Whenever possible, apps will retrieve data from ElastiCache and defer to databases when data isn't found in cache.
You can abstract the HTTP sessions from the web servers themselves, and a common solution for this is to leverage an in-memory key/value store such as Redis, Memcached or Dynamo DB.
You are concerned about response times for your customer
You find heavy-hitting, high-volume requests inundating your database
You would like to reduce your database costs
2 Forms to manage with ElasticCache:
Write through: The write-through strategy adds data or updates data in the cache whenever data is written to the database. Advantages:Every write involves two trips: A write to the cache & A write to the database, Disadvantages: Missing data ( If you spin up a new node, whether due to a node failure or scaling out, there is missing data.), and Cache churn (Most data is never read, which is a waste of resources)
Lazy loading: lazy loading is a caching strategy that loads data into the cache only when necessary. Advantages: Only requested data is cached, and Node failures aren't fatal for your application. Disadvantages: There is a cache miss penalty. Each cache miss results in three trips, and Stale data.
Content