Exemplo n.º 1
0
        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");
            }
        }
Exemplo n.º 2
0
        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}"));
        }