/// <inheritdoc/> public async Task <ServiceResponse <TResult> > GetAsync <TResult>(string cacheKey) { string cacheResult = null; try { cacheResult = await distributedCache .GetStringAsync(cacheKey) .ConfigureAwait(false); if (string.IsNullOrWhiteSpace(cacheResult)) { return(ServiceResponseHelper.WithResult(default(TResult))); } var settings = new JsonSerializerSettings().GetJsonSerializerSettingsWithPrivateCamelCaseSerializer(); var deserializedObject = JsonConvert.DeserializeObject <TResult>(cacheResult, settings); return(ServiceResponseHelper.WithResult(deserializedObject)); } catch (Exception ex) { logger.LogError(ex, $"[{nameof(CacheHelper)}] Fail using {nameof(GetAsync)} for result {typeof(TResult).FullName}: {ex.Message}"); return(ServiceResponseHelper.WithError <TResult>(new Error { Message = HttpMessage.CACHE_MESSAGE_FAIL, Exception = ex })); } }
/// <inheritdoc/> public async Task <ServiceResponse <byte[]> > GetByteAsync(string cacheKey) { byte[] cacheResult = null; try { cacheResult = await distributedCache .GetAsync(cacheKey) .ConfigureAwait(false); if (cacheResult == null) { return(ServiceResponseHelper.WithResult(default(byte[]))); } return(ServiceResponseHelper.WithResult(cacheResult)); } catch (Exception ex) { logger.LogError(ex, $"[{nameof(CacheHelper)}] Fail using {nameof(GetByteAsync)} for result {typeof(byte[]).FullName}: {ex.Message}"); return(ServiceResponseHelper.WithError <byte[]>(new Error { Message = HttpMessage.CACHE_MESSAGE_FAIL, Exception = ex })); } }