我想我通过如下更新代码成功地解决了这个问题:
public object CachedMethodCall(MethodInfo realMethod, params object[] realMethodParams)
{
string cacheKey = CachingHelper.GenereateCacheKey(realMethod, realMethodParams);
object result = _CacheManager.GetData(cacheKey);
if (result == null)
{
result = realMethod.Invoke(_RealService, BindingFlags.InvokeMethod, null, realMethodParams, CultureInfo.InvariantCulture);
// TODO: currently cache expiration is set to 5 minutes. should be set according to the real data expiration setting.
AbsoluteTime expirationTime = new AbsoluteTime(DateTime.Now.AddMinutes(5));
_CacheManager.Add(cacheKey, result, CacheItemPriority.Normal, null, expirationTime);
}
return result;
}
我注意到前一个
_CacheManager.Contains
调用有时返回true,即使缓存不包含数据。我怀疑线程导致了问题,但我不确定。。。