Look-Aside Cache vs. Inline Cache
Look-Aside Cache
How it reads
- Application requests data from cache
- Cache delivers data, if available
- If data not available, application gets data from backing store and writes it to the cache for future requests (read aside)
How it writes
• Application writes new data or updates to existing data in both the cache and the backing store -or- all writes are done to the backing store and the cache copy is invalidated
Examples
Amazon ElastiCache (Memcached and Redis) or libraries like Ehcache and Google Guava for in-memory caches
Inline Cache(Cache through)
How it reads
- Application requests data from cache
- Cache delivers data if available
- Key Difference: If data not available, cache retrieves data from backing store (read thru), caches it, then returns the value to the requesting application
How it writes
- Application writes new data or updates existing data in cache
- Cache will synchronously (write through) or asynchronously (write behind) write data to the backing store
Examples
Application-specific implementations like Amazon DynamoDB Accelerator (DAX) and standards-based implementations like HTTP caching (either with a local caching client or an external cache server like Nginx or Varnish).
levels of cache
if we implemented a service API operation that retrieved product information by product ID, the code might look like the following example. This code looks up product info in a local cache, followed by a remote cache, followed by a database: