Exemple #1
0
        public CacheService(IMemoryCache memoryCache, IConfigurationRoot configuration)
        {
            if (bool.TryParse(configuration["RedisCache:Enabled"], out var redisCacheEnabled) &&
                redisCacheEnabled)
            {
                _redisCacheManager = new RedisCacheManager <TModel>(configuration);
            }

            if (bool.TryParse(configuration["InMemoryCache:Enabled"], out var inMemoryCacheEnabled) &&
                inMemoryCacheEnabled)
            {
                _inMemoryCache = new InMemoryCacheManager <TModel>(memoryCache, configuration);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureKeyVaultClient"/> class.
        /// </summary>
        /// <param name="vaultUrl">
        /// The vault url.
        /// </param>
        /// <param name="clientId">
        /// The client id.
        /// </param>
        /// <param name="certificate">
        /// The client certificate.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The parameters can not be empty
        /// </exception>
        public AzureKeyVaultClient(string vaultUrl, string clientId, X509Certificate2 certificate)
        {
            if (string.IsNullOrEmpty(vaultUrl))
            {
                throw new ArgumentNullException(nameof(vaultUrl));
            }

            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            if (certificate == null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }

            this.vaultUrl          = vaultUrl;
            this.clientId          = clientId;
            this.clientCertificate = new ClientAssertionCertificate(this.clientId, certificate);
            this.cacheManager      = new InMemoryCacheManager();

            this.keyVaultClient = new KeyVaultClient(this.GetTokenByCertificateAsync);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureKeyVaultClient"/> class.
        /// </summary>
        /// <param name="vaultUrl">
        /// The vault url.
        /// </param>
        /// <param name="clientId">
        /// The client id.
        /// </param>
        /// <param name="clientSecret">
        /// The client secret.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The parameters can not be null or empty.
        /// </exception>
        public AzureKeyVaultClient(string vaultUrl, string clientId, string clientSecret)
        {
            if (string.IsNullOrEmpty(vaultUrl))
            {
                throw new ArgumentNullException(nameof(vaultUrl));
            }

            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            if (clientSecret == null)
            {
                throw new ArgumentNullException(nameof(clientSecret));
            }

            this.vaultUrl     = vaultUrl;
            this.clientId     = clientId;
            this.clientSecret = clientSecret;
            this.cacheManager = new InMemoryCacheManager();

            this.keyVaultClient = new KeyVaultClient(this.GetTokenBySecretAsync);
        }
 public MultiLayerCacheService(IMemoryCache memoryCache, IConfigurationRoot configuration)
 {
     _redisCacheManager = new RedisCacheManager <TModel>(configuration);
     _inMemoryCache     = new InMemoryCacheManager <TModel>(memoryCache, configuration);
 }
        public void ReadWriteIntoInMemoryCache(IMemoryCache memoryCache, IConfigurationRoot configuration)
        {
            ICacheManager <string, UserForCaching> cache = new InMemoryCacheManager <UserForCaching>(memoryCache, configuration);

            RunTest(cache);
        }