views:

247

answers:

1

Hi guys

I want to do some caching at the data access layer to help boost performance. I have decided that I will use the HTTPContext cache, with an abstraction layer on top so i can switch in and out other caching strategies later on if needed.

Basically the cache should be variant, meaning that for each individual method it will cache a different result based on the values that are passed in.

My question is given that if I am wanting to have a "cache per function" and for the system to determine whether to hit the database or the cache based on the values that are being passed into the method, how would I go about doing this (i.e. taking a hash of the items values or something - but there must be a better way).

I know that I could do some stuff with cross cutting concerns and the EL and the Caching Application Block, but the overhead of that is a little more than I am looking for. I am wanting to do something fairly light weight and that I can control (i.e. i could pass in a parameter that I could check which would bypass the cache - for instance)

Cheers Anthony

+1  A: 

We use Enterprise Library Caching Application Block for this. Entlib Cache works like a dictionary with a key and a value.

Entlib cache allows you to create several named caches, in your case it would be one per function.

Within each cache you can use the parameters as the key. You can then do it as follows:

  • Try to get value from cache based on key.
  • If value is null, it is missing from the cache.
  • Therefore, get value from database and place the result in the cache, so that it is available next time.
Shiraz Bhaiji