public static ApiKeyLoginResponseContent GetOrSetAuthorization(string tenantUid) { var cacheInfo = new CacheInfo() { CacheName = AUTH_KEY, TenantUid = tenantUid }; var result = CacheHelper.GetCache <ApiKeyLoginResponseContent>(cacheInfo); if (result == null || result.Expires <= DateTime.UtcNow) { CacheHelper.ClearCache(cacheInfo); result = CacheHelper.GetOrSetCache <ApiKeyLoginResponseContent>(cacheInfo, () => { var key = ApiKeyCache.GetByTenantUid(tenantUid); var apiService = new TotalCodeApiService(); var res = (ApiKeyLoginResponseContent)apiService.ApiKeyLogin(key.ApiKey, key.AppId); return(res); }, TimeSpan.FromSeconds(CacheSetting.TimeoutInSeconds)); } return(result); }
private ApiKeyLoginResponseContent GetAuthorization(ApiKeys key) { DateTime now = DateTime.UtcNow; ApiKeyLoginResponseContent response = (ApiKeyLoginResponseContent)Session["authorization"]; if (response == null || response.Expires <= now) { response = (ApiKeyLoginResponseContent)apiService.ApiKeyLogin(key.ApiKey, key.AppId); Session["authorization"] = (ApiKeyLoginResponseContent)response; } return(response); }