private T GetCached <T>(string scope, string key, bool isVolatile, IAuthHandler authHandler, Func <T> func) where T : class { var cache = Settings.CacheFactory?.Get <T>(); T result; if (authHandler.Authorize(scope)) { if (cache != null && cache.TryGet(key, out result)) { #if DEBUG Console.WriteLine($"Cache hit {key}"); #endif return(result); } else { #if DEBUG Console.WriteLine($"Cache miss {key}"); #endif result = func(); cache?.Set(key, result, isVolatile ? Settings.VolatileTtl : Settings.StaticTtl); return(result); } } else { throw new AuthenticationException("The request could not be authorized."); } }