/// <summary> /// Checks if a key is in the cache and if not /// Retrieves raw counter data from Environment Variables /// Cleans raw JSON for only requested counter /// Creates value for caching. /// </summary> /// <param name="name">Cache key and name of the counter to be selected from JSON.</param> /// <param name="environmentVariable">Identifier of the environment variable.</param> /// <returns>Value from cache.</returns> public long GetCounterValue(string name, AzureWebApEnvironmentVariables environmentVariable) { if (!CacheHelper.Instance.IsInCache(name)) { PerformanceCounterImplementation client = new PerformanceCounterImplementation(); string uncachedJson = client.GetAzureWebAppEnvironmentVariables(environmentVariable); if (uncachedJson == null) { return(0); } CacheHelper.Instance.SaveToCache(name, uncachedJson, DateTimeOffset.Now.AddMilliseconds(500)); } string json = this.GetFromCache(name).ToString(); long value = PerformanceCounterValue(name, json); return(value); }
/// <summary> /// Checks if a key is in the cache and if not /// Retrieves raw counter data from Environment Variables /// Cleans raw JSON for only requested counter /// Creates value for caching. /// </summary> /// <param name="name">Cache key and name of the counter to be selected from JSON.</param> /// <param name="environmentVariable">Identifier of the environment variable.</param> /// <returns>Value from cache.</returns> public long GetCounterValue(string name, AzureWebApEnvironmentVariables environmentVariable) { if (!CacheHelper.Instance.IsInCache(name)) { PerformanceCounterImplementation client = new PerformanceCounterImplementation(); string uncachedJson = client.GetAzureWebAppEnvironmentVariables(environmentVariable); if (uncachedJson == null) { return 0; } CacheHelper.Instance.SaveToCache(name, uncachedJson, DateTimeOffset.Now.AddMilliseconds(500)); } string json = this.GetFromCache(name).ToString(); long value = this.PerformanceCounterValue(name, json); return value; }