public override void OnInvoke(MethodInterceptionArgs methodInterceptionArgs)
{
if (Action == CacheAction.Add)
{
var cacheKey = BuildCacheKey(methodInterceptionArgs);
if (Cache[cacheKey] != null)
{
methodInterceptionArgs.ReturnValue = Cache[cacheKey];
}
else
{
lock (_syncRoot)
{
if (Cache[cacheKey] == null)
{
var returnVal = methodInterceptionArgs.Invoke(methodInterceptionArgs.Arguments);
methodInterceptionArgs.ReturnValue = returnVal;
Cache[cacheKey] = returnVal;
}
else
{
methodInterceptionArgs.ReturnValue = Cache[cacheKey];
}
}
}
}
else
{
var typeName = GetTypeName(methodInterceptionArgs.Binding.GetType());
lock (_syncRoot)
{
Cache.Remove(typeName);
}
methodInterceptionArgs.ReturnValue = methodInterceptionArgs.Invoke(methodInterceptionArgs.Arguments);
}
}