0
votes

we have a project built upon WCF RIA Services. Imagine that we have a method with multiple arguments passed into, and producing different set of items depending on arguments, for example:

 IQueryable<PresentationEntity> GetEntities(DateTime startDate, DateTime endDate, int maxCount)
{
...
}

The question is what is the best way to set up caching for this method to cache all the outputs depending on parameter values?

1

1 Answers

0
votes

I've done this before by simply concatenating all the parameters together to form a string, which will serve as your cache key.

Some things to note, consider:

  1. For any objects you may pass in, you'll want to override ToString() so that the object is represented uniquely as a string. Possibly just concatenate the properties together or use something like Java's hash code property.

  2. Order can introduce bugs, so make sure you concatenate them together in the same order each time.

  3. You can explore some AOP frameworks that allow you to write code that is cross cutting. This just means you don't have to litter your code with a ton of "if (!InCache(key)) { ... }" statements at the top of each WCF call.