I have a need to pass a delegate method with a varying number and type of parameters to another method. My hope is to be able to inspect the values of the parameters within the call.
This is my generic cache class.
public T Get<T>(Expression<Func<T>> getItemCallback) where T : class
{
T item = HttpRuntime.Cache.Get(hashRepresentationOfValues) as T;
if (item == null)
{
item = getItemCallback.Compile()();
HttpRuntime.Cache.Insert(
hashRepresentationOfValues,
item,
null,
DateTime.Now.AddMinutes(5),
TimeSpan.Zero);
}
return item;
}
My calls look like the following:
private DataContext db;
return cache.Get<List<SomeDBObject>>(
() => db.SomeDBObjectCall(param1, param2, param3));
As you can see it would be extremely helpful if I could dynamically determine the values of the delegate call as they could be used as the cache-key.