public static string ToESchemaTypePrefix(this ESchemaType value, string applicationVersion) { switch (value) { case ESchemaType.FormJson: return($"form-json-{applicationVersion}-"); case ESchemaType.PaymentConfiguration: return("paymentconfig-"); default: throw new Exception("Unknown schema type"); } }
public async Task <T> GetFromCacheOrDirectlyFromSchemaAsync <T>(string cacheKey, int minutes, ESchemaType type) { T result; var prefix = type == ESchemaType.PaymentConfiguration ? "payment-config/" : string.Empty; if (_distributedCacheConfiguration.Value.UseDistributedCache && minutes > 0) { var data = _distributedCache.GetString($"{type.ToESchemaTypePrefix(_configuration["ApplicationVersion"])}{cacheKey}"); if (data == null) { result = await _schemaProvider.Get <T>($"{prefix}{cacheKey}"); if (result != null) { await _distributedCache.SetStringAsync($"{type.ToESchemaTypePrefix(_configuration["ApplicationVersion"])}{cacheKey}", JsonConvert.SerializeObject(result), minutes); } return(result); } return(JsonConvert.DeserializeObject <T>(data)); } return(await _schemaProvider.Get <T>($"{prefix}{cacheKey}")); }