Cloud-Design Pattern:-Cache-aside

If we need to describe this in one scentance its “Load data on demand in cache from a data store”

This pattern can scalup the performance and also helps to maintain consistency between data held in cache & the data in the underlying data store.

Context and problem

Lets say we have a system which use cache for better and continues access to information held in database/ data store.How ever it is not pratical to expect that every the data in cache will always be consistence with database/ data store.

Here App should implement some strategy that will help to ensure that the data in the cache is up to date as far as possible. Further should also dectect and handle situations which can/May arise when data in cache has become stagnant.


Many product in the market provide caching system in which we have read-through write-through/write-behind operations.

In most of these system,an application retrieves data by  referencing the cache. If no data in cache,it is transparently retrive data and add to cache,So any modification to data held in cache is auto written back to data store as well.

For cache that dosent provide this functionality,Application is responsible for this.

An App can emulate the functionality  od read-through caching by implementing the cache -aside strategy. the strategy loads data into cache on demand.

If an application updates information it can do write-through strategy as follows:

  • Make the modification to store
  • Invalidate the corresponding item in cache.

When you need next item, using case aside strategy will cause the updated data to be retrived from the data store and added back into the cache.

Issue and considration:

Consider following point when desciding to implement his pattern

  • Lifetime of Cached data
  • Evucting Data
  • Priming the cache
  • consistency
  • In-Memory Caching

When To use This Pattern

  • A cache does not provide native read-through and write-through operations
  • Resource demand is unpredictable

Not suitale in following case

  • When cached data set is static
  • For Caching session state information is in a web application hosted in web farm


Back To Blogging with Cloud

After a break of more than a years with busy schedule today i got a chance to get back into Blogging. I myself was awating for a new blog to post for my followers and friends.

As a fresh start now i will com up with the blogs on Azure Clouds and design patterns. For a quick Summarise following topics i will be covering in next few weeks.

  1. Cache-Aside Pattern
  2. Circuit Breaker Pattern
  3. Compensating Transaction Pattern
  4. Competing Consumers Pattern
  5.  Compute Resource Consolidation Pattern
  6. Command and Query Responsibility Segregation (CQRS) Pattern.

Friend Assemblies in C#

While going through the CLR via C# book i came a across a topic Friend Assemblies, What exactly is the Friend Assemblies ?

Lets understand it by an example given in the book suppose we are Application for which we have 2 different teams named Team Alpha and Team Beta.

Team Alpha, that is defining a bunch of utility types in one assembly, and they expect these types to be used by members in another team, Team Beta.

For various reasons such as time schedules or geographical location, or perhaps different cost centers or reporting structures, these two teams cannot build all of their types into a single assembly; instead, each team produces its own assembly file.

In order for Team Beta’s assembly to use Team Alpha’s types, Team Alpha must define all of their utility types as public. However, this means that their types are publicly visible to any and all assemblies; developers in another company could write code that uses the public utility types, and this is not desirable. Maybe the utility types make certain assumptions that Team Beta ensures when they write code that uses Team Alpha’s types. What we’d like to have is a way for Team Alpha to define their types as internal while still allowing Team Beta to access the types. The CLR and C# support this via friend assemblies. This friend assembly feature is also useful when you want to have one assembly containing code that performs unit tests against the internal types within another assembly.

When an assembly is built, it can indicate other assemblies it considers “friends” by using the InternalsVisibleTo attribute defined in the System.Runtime.CompilerServices namespace.The attribute has a string parameter that identifies the friend assembly’s name and public key (the string you pass to the attribute must not include a version, culture, or processor architecture). Notethat friend assemblies can access all of an assembly’s internal types as well as these type’s internalmembers. Here is an example of how an assembly can specify two other strongly named assemblies

named “Assmblytest” and “Nirbhay” as its friend assemblies:

using System;

using System.Runtime.CompilerServices; // For InternalsVisibleTo attribute

// This assembly’s internal types can be accessed by any code written

// in the following two assemblies (regardless of version or culture):

[assembly:InternalsVisibleTo(“Assmblytest, PublicKey=12345678…90abcdef”)]

[assembly:InternalsVisibleTo(“Nirbhay, PublicKey=b77a5c56…1934e089”)]

internal sealed class SomeInternalType { … }

internal sealed class AnotherInternalType { … }

Accessing the above assembly’s internal types from a friend assembly is trivial. For example,

here’s how a friend assembly called “Assmblytest” with a public key of “12345678…90abcdef” can access the internal type SomeInternalType in the assembly above.