Caching Design

Discussion in 'ASP.NET 2.0' started by strazz, Mar 20, 2006.

  1. I have a general question about how I should design caching for my website. I feel as if I have a unique situation:

    3 to 4mb of database data that is updated about once per hour.

    I know when the data gets updated (a C# function is called), and I can repopulate the cache then. I am going to implement caching on this, I'm just not sure how to attack it:

    1. What if I stored a 3mb DataSet object in cache?
    -I'm a little nervous about this one, it seems like it could be scary for memory usage, would each webform that uses this cache object take up 3mb of memory? I would just make a dataview and use the .Find() methods, etc. to get my data.

    2. What if I stored all of the queries in the Cache as the final objects (provided the class is Serializable)?

    -This will require explanation, let's say I have a query that takes 3 parameters: getEmployees(string hairColor, string officeLocation) I could cache this query like this:

    string key = 'employees' + '-' + 'hairColor' + '-' + 'officeLocation';
    Employee employee = Cache[key];
    if (employee == null)
    repopulate()

    The only issue I see here is a pretty large number of Cache objects, but the advantage is they are all really tiny. I'm worried about the performance implications of like 2000 objects in cache, will the locating by key take a long time or is it probably like a really fast red-black tree doing the searching in the background?

    So the bottom line is: One large dataset in Cache vs. Many many tiny objects in Cache.
     
  2. What Database is used on the backend?

    If SQL 2005 check out SqlCacheDependency, this is a pretty sweet method of automatically updating your Cached data if anything changes in the database for that Cache... Very slick.

    Just a possible starter...
     
  3. Im using 05 and I've definitely checked that out, I've been advised in another forum to go with the approach of lots of items in the cache. For those individual items I may go with a sqlcachedependency. Thanks for the reply.
     
  4. Oh, one more thing Robert;
    In the grand scheme of things, 3mb cache data really isn't that much, I mean, typical server these days is running with at least 2GB of RAM, we are taking like maybe 2 tenths of a percent of available resources... (what is each site alotted here at Discount I wonder?)
    Personally, I would opt for the dataset vs. many tiny objects since maintainability is a little more simplistic, and only one point of possible failure, versus many.

    Also, the cache when created properly, isa global cache, you have 50 users that are all hitting the same form that calls that cached dataset, there is only one 3mb dataset cached object, not 50, so your cool there. (The beauty of the cache concept).

    I am not sure why your situation is demanding to cache such a large (relatively speaking) amount of data, interestin performance boost (squeezing every last drop from the orange)?It is also important to ask, "Will that data ever grow larger?", and the answer there may spark you to rethink caching this data, or not. I mean could it ever grow to 20MB? Things could get interesting when weighting the current benefitto whatthe application might be in say 2 years.

    Just my 2 centavos!
    BZ
     

Share This Page