开发者

When and how to go about performing caching in asp.net mvc?

开发者 https://www.devze.com 2023-01-23 00:06 出处:网络
UPDATE : I also found ncache which seems useful and also came to know that stackoverflow uses redis for caching. I also have come across memcached and seems one of the better 开发者_开发知识库alternat

UPDATE : I also found ncache which seems useful and also came to know that stackoverflow uses redis for caching. I also have come across memcached and seems one of the better 开发者_开发知识库alternatives.

I have found this but I needed to know what are the ways in which I can cache some of my LINQ queries and use them efficiently. I found Output cache in asp.net mvc are there other ways to do caching?

I am kind of a newbie and never done caching before so I would appreciate if anyone can point me in the right direction here? Mainly I want answer to when would be caching necessary and how to go about doing caching in asp.net mvc ?


In my experience application level caching is rarely the correct approach to fixing performance issues and it nearly always causes more problems than it solves.

Before you embark on any caching you should first:

(i) profile your application and the queries it makes to see if you can address them directly (e.g. query patterns that are too wide (fetching columns that aren't displayed) or too deep (e.g. fetching more rows than you display), too frequent (lazy loading might be causing more round trips than you need), too expensive (poor table design might mean more joins than you need), or the tables themselves might not be indexed correctly;

(ii) take a holistic look at your web site and the user experience to see how you can improve the perceived performance (e.g. set proper browser-level cache cache headers on static content). Using AJAX might and a paged grid view like jQGrid might eliminate many database accesses while a user is paging through records because the rest of the page content is not changing.

After you've exhausted fixing the real problem you may then then be ready to consider caching.

But before you do, make a simple calculation: how much does an upgraded server cost vs the development and testing time you will spend implementing caching and tracking down odd stale-cache issues? Sometimes it's cheaper just to upgrade...

0

精彩评论

暂无评论...
验证码 换一张
取 消