public void Intercept(IInvocation invocation) { //Capture method information string methodName = invocation.Method.Name; string parameters = string.Join(",", invocation.Arguments.Select(a => (a ?? "").ToString())); //Log method invocation _logger.Log($"Method {methodName} with parameters {parameters} was invoked"); //Proceed with method execution invocation.Proceed(); }
public void Intercept(IInvocation invocation) { //Capture method information string cacheKey = $"{invocation.Method.Name}:{string.Join(",", invocation.Arguments.Select(a => (a ?? "").ToString()))}"; //Check if cached result exists if (_cache.TryGetValue(cacheKey, out var result)) { //Return cached result invocation.ReturnValue = result; return; } //Proceed with method execution invocation.Proceed(); //Cache result _cache.Set(cacheKey, invocation.ReturnValue, _cacheOptions); }