views:

43

answers:

1

Hi

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

Thanks

+3  A: 

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.

Eilon
Or maybe it takes 0.001 second but 1000 users accessing it, so latest user will be have bad performance, but I am actually talking about a specific scenario, where most of data are cheap to generate and related only to one user. I don't think I should consider caching for this app except for lookups. what do u think?
Costa