Cache-Aside Pattern

Cache is used by applications to optimize the repeated data access from data store like DB. Caching is effective for either relatively static data or the data that is read frequently.

In this pattern application is only responsible for reading and writing data from the database.Cache is kept aside and it does  not interact directly with the database. The cache is kept as in-memory data enabling faster and better data scaling.

  • This Pattern is about loading data into cache from data store on demand
  • This pattern helps in performance and also on maintaining the consistency of cache data with the data store.
  • It supports read-through, write-through and write-behind operations
  • Applications should take care of maintaining the consistency of data and also detect and handle data when it becomes stale.
  • The principle of  the pattern is
    • Check if the requested data is available in the cache first .
    • If not then retrieve the data from the data store and also update the cache with the data
    • If the data is modified in the cache then that data needs to be persisted in the data-store.
  • It is very powerful and allows usage of complex DB queries involving joins and nested queries.

Important point to consider while using this pattern

  1. Lifetime of cached data – Do not make expiration date too short or too long . Customize based on the data  access pattern of the application
  2. Removing/cleaning the cache
  3. Cache-aside pattern will not be suitable for applications which requires data to be pre-populated .  It may still be valid if those data gets removed and pre-populated during the application run-time.
  4. In-Memory caching – applicable if the applications has repeated access to the cache. Most appropriate for this scenario would be shared or distributed caching

Suitable scenario for using this pattern

  1. When the cache does not provide a native read-through or write-through operation
  2. On Demand cache population

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Cheat Sheet To JAVA Latest Technology

%d bloggers like this: