Posted in Questions, Solutions

Best location to implement caching?

There was a question at Server Side .net about best place to implement caching at  It questions the best location to implement Caching – UI, Business or the Data Layer. This is my opnion.

I think to answer that, you need to understand the word Cache. There are lot of definitions out there. I treat its as:

Remembering the result of a frequently executed task

So the best place is the place whereever there is less change in result considering loads. So potentially you can end up implementing Caching mechanisums in multiple layers. Which i think its good and required for high demand systems, just don’t double cache (cache same task’s result in multiple layers, unless you really neeed it).

Data layer senario: if you are quering your DB frequently and the data does not change much, then it makes sense to put cache in data layer.

Business Logic Layer: If your result does not change often for requests, then this is good place.

Presentation Layer: If your UI does not change, then this is the place. There are situations where you Cache at Data/Business Layers, if the resulting data is same, but the presentation is different based on user’s preferences – Themes say like Tree View, Grid View and so on.

.net has various Caching mechanisums for various levels, see for more info


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s