开发者

Caching lightweight data

开发者 https://www.devze.com 2022-12-16 12:03 出处:网络
What is the point of caching a one row of data, especially if it will probably needed once or twice on its life time.开发者_StackOverflow中文版Or I should cache everything. and why?

What is the point of caching a one row of data, especially if it will probably needed once or twice on its life time. 开发者_StackOverflow中文版Or I should cache everything. and why?

Thanks


If that row of data takes 5 hours to compute then it might be worth it. If it takes 0.001 seconds to compute then it probably isn't worth it.

Most cache systems (including the one in ASP.NET) let you set a cache policy on the item being cached. If it was cheap to compute then mark it as a low priority cache item. If it was very expensive then you can mark it as high priority and thus try to keep it in the cache as long as possible.

Here's an overload of Cache.Insert that allows you to specify the relative priority:

public void Insert(
    string key,
    Object value,
    CacheDependency dependencies,
    DateTime absoluteExpiration,
    TimeSpan slidingExpiration,
    CacheItemPriority priority,
    CacheItemRemovedCallback onRemoveCallback
)

The more we understand the scenario the more precise of an answer we can provide.

In general, if the data is small and per-user then caching is not recommended since there is little to be saved.

As with all performance considerations, first define your performance goals, then see if you meet them. If you don't meet them then you have to measure your app to see where the costs are being incurred and then improve those places until you meet your goals.

0

精彩评论

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