I have a cache method which is
public TReturn Get<TParam, TReturn>(string cacheId, Func<TParam, TReturn> getItemCallback, TParam argument)
where TReturn : class
where TParam : class
{
TReturn item = (TReturn)HttpRuntime.Cache.Get(cacheId);
if (item == null)
{
item = getItemCallback(argument);
HttpContext.Current.Cache.Insert(cacheId, item);
}
return item;
}
and i try to use it and it seem ive got no luck here… normally it should work. I am using it this way.
public List<LookupParameter> GetAllLookupEntries(string tableContext)
{
return _cacheProvider.Get<string,List<LookupParameter>>("",
_lookupTableRepository.GetAllLookupEntries(tableContext), "");
}
It say it can’t convert System.Collections.Generic.List<Pyrosphere.Providers.LookupParameter> to System.Func<string,System.Collections.Generic.List<Pyrosphere.Providers.LookupParameter>>
Any idea ?
The problem is your passing a
List<string>as the second parameter and it’s expecting aFunc<string, List<string>>. Try passing the second argument as a lambda expressionAlso it may be a bit simpler if you change your
Getfunction to not take an argument. The argument is provided to theGetmethod and then immediately passed back to the delegate with nothing else done in between. So the callsite could be much simpler by having it handle the argument directly. For example