string BuildCacheKey(IMethodContextAdapter methodContext) { var key = methodContext.MethodName; foreach (var argument in methodContext.Arguments) key += "_" + argument.ToString(); return key; }
public void OnSuccess(IMethodContextAdapter methodContext) { var cacheKey = (string)methodContext.Tag; Console.WriteLine("[Cache] storing value for {0}", cacheKey); _cache[cacheKey] = methodContext.ReturnValue; }
string BuildCacheKey(IMethodContextAdapter methodContext) { var key = methodContext.MethodName; foreach (var argument in methodContext.Arguments) { key += "_" + argument.ToString(); } return(key); }
public void OnEntry(IMethodContextAdapter methodContext, string role) { Console.WriteLine("[Auth] Checking if user is in {0} role", role); if (UserIsInRole(role)) { Console.WriteLine("[Auth] User IS authorized"); return; } Console.WriteLine("[Auth] User is NOT authorized"); methodContext.AbortMethod(); UnauthorizedAccess(); }
public void OnEntry(IMethodContextAdapter methodContext) { var cacheKey = BuildCacheKey(methodContext); if (!_cache.ContainsKey(cacheKey)) { Console.WriteLine("[Cache] MISS for {0}", cacheKey); methodContext.Tag = cacheKey; return; } Console.WriteLine("[Cache] HIT for {0}", cacheKey); methodContext.ReturnValue = _cache[cacheKey]; methodContext.AbortMethod(); }