开发者

ASP.NET MVC 3: what and when to cache and how to decide?

开发者 https://www.devze.com 2023-02-21 03:57 出处:网络
I hav开发者_Python百科e been neglecting learning about caching for quite some time now, and although I\'ve used caching here and there in the past it\'s not something I\'m familiar with.

I hav开发者_Python百科e been neglecting learning about caching for quite some time now, and although I've used caching here and there in the past it's not something I'm familiar with.

I found a great tutorial about what caching is and what kinds of cache there are (I know already what caching is), but...

How does one decide what and when to cache? Are there things that should always be cached? On what situations should you never use caching?


First rule is: Don't cache until you need it, that would be premature optimization (first link I found, google for more info)

The biggest problem with caching is invalidation of cache. What happens when the data you have cached is being updated. You need to make sure your cache is updated as well and if not done correctly often becomes a mess.

I would:

  1. Build the application without caching and make sure the functionality works as intended
  2. Do some performance testing, and apply caching when needed
  3. After applying caching do performance testing again to check that you are getting the expected speed increase


I think the easiest way is to ask yourself a bunch of questions,

Is this result ever going to change?

No? then cache it permanently

Yes, When is it going to change? When a user updates something. Is it going to impact only the particular user who changed the value or all of the users. This should give you an indication of when to clear the particular cache.

You can keep on going, but after awhile you will end up with different profiles UserCache, GlobalCache just being 2 examples. These profiles should be able to tell you what to cache and have a certain update criteria (When to refresh the cache)

0

精彩评论

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