/// <summary>
 /// Used internally only for unit testing.
 /// </summary>
 /// <param name="innerHandler">The inner handler to retrieve the content from on cache misses.</param>
 /// <param name="cacheExpirationPerHttpResponseCode">A mapping of HttpStatusCode to expiration times. If unspecified takes a default value.</param>
 /// <param name="cache">The distributed cache to use.</param>
 /// /// <param name="statsProvider">An <see cref="IStatsProvider"/> that records statistic information about the caching behavior.</param>
 internal RedisCacheHandler(HttpMessageHandler innerHandler, IDictionary<HttpStatusCode, TimeSpan> cacheExpirationPerHttpResponseCode, IDistributedCache cache,
     IStatsProvider statsProvider = null) : base(innerHandler ?? new HttpClientHandler())
 {
     this.StatsProvider = statsProvider ?? new StatsProvider(nameof(RedisCacheHandler));
     this.cacheExpirationPerHttpResponseCode = cacheExpirationPerHttpResponseCode ?? new Dictionary<HttpStatusCode, TimeSpan>();
     responseCache = cache;
 }
 public DynamicCacheShapeDisplayEvents(
     IDistributedCache distributedMemoryCache,
     ICacheContextManager cacheContextManager)
 {
     _distributedMemoryCache = distributedMemoryCache;
     _cacheContextManager = cacheContextManager;
 }
        public CachingUserRepository(
            IDistributedCache cache,
            IUserRepository implementation)
        {
            this.cache = cache;
            this.implementation = implementation;

        }
        public DistributedTreeCache(
            IDistributedCache cache,
            IOptions<TreeCacheOptions> optionsAccessor = null)
        {
            if (cache == null) { throw new ArgumentNullException(nameof(cache)); }
            this.cache = cache;

            options = optionsAccessor?.Value;
            if (options == null) options = new TreeCacheOptions(); //default
        }
Example #5
0
 public DistributedSession([NotNull] IDistributedCache cache, [NotNull] string sessionId, TimeSpan idleTimeout,
     [NotNull] Func<bool> tryEstablishSession, [NotNull] ILoggerFactory loggerFactory, bool isNewSessionKey)
 {
     _cache = cache;
     _sessionId = sessionId;
     _idleTimeout = idleTimeout;
     _tryEstablishSession = tryEstablishSession;
     _store = new Dictionary<EncodedKey, byte[]>();
     _logger = loggerFactory.CreateLogger<DistributedSession>();
     _isNewSessionKey = isNewSessionKey;
 }
        public SwiftAuthManagerDistributedCache(IOptions<SwiftServiceOptions> options, IDistributedCache cache)
        {
            var _options = options.Value;
            Credentials = new SwiftCredentials {
                Endpoints = _options.Endpoints,
                Password = _options.Password,
                Username = _options.Username
            };

            _cache = cache;
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SitemapService" /> class.
 /// </summary>
 /// <param name="cacheProfileSettings">The cache profile settings.</param>
 /// <param name="distributedCache">The distributed cache for the application.</param>
 /// <param name="logger">The <see cref="SitemapService"/> logger.</param>
 /// <param name="urlHelper">The URL helper.</param>
 public SitemapService(
     IOptions<CacheProfileSettings> cacheProfileSettings,
     IDistributedCache distributedCache,
     ILogger<SitemapService> logger,
     IUrlHelper urlHelper)
 {
     CacheProfile cacheProfile = cacheProfileSettings.Value.CacheProfiles[CacheProfileName.SitemapNodes];
     this.expirationDuration = TimeSpan.FromSeconds(cacheProfile.Duration.Value);
     this.distributedCache = distributedCache;
     this.logger = logger;
     this.urlHelper = urlHelper;
 }
 public static IApplicationBuilder UseDistributedSession([NotNull] this IApplicationBuilder app, 
     IDistributedCache cache, Action<SessionOptions> configure = null)
 {
     var loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
     return app.UseSession(options =>
     {
         options.Store = new DistributedSessionStore(cache, loggerFactory);
         if (configure != null)
         {
             configure(options);
         }
     });
 }
 /// <summary>
 /// Initializes a new instance of <see cref="Tailspin.Surveys.TokenStorage.DistributedTokenCacheService"/>
 /// </summary>
 /// <param name="contextAccessor">An instance of <see cref="Microsoft.AspNetCore.Http.IHttpContextAccessor"/> used to get access to the current HTTP context.</param>
 /// <param name="loggerFactory"><see cref="Microsoft.Extensions.Logging.ILoggerFactory"/> used to create type-specific <see cref="Microsoft.Extensions.Logging.ILogger"/> instances.</param>
 /// <param name="dataProtectionProvider">An <see cref="Microsoft.AspNetCore.DataProtection.IDataProtectionProvider"/> for creating a data protector.</param>
 public DistributedTokenCacheService(
     IDistributedCache distributedCache,
     IHttpContextAccessor contextAccessor,
     ILoggerFactory loggerFactory,
     IDataProtectionProvider dataProtectionProvider)
     : base(loggerFactory)
 {
     Guard.ArgumentNotNull(distributedCache, nameof(distributedCache));
     Guard.ArgumentNotNull(contextAccessor, nameof(contextAccessor));
     Guard.ArgumentNotNull(dataProtectionProvider, nameof(dataProtectionProvider));
     _distributedCache = distributedCache;
     _contextAccessor = contextAccessor;
     _dataProtectionProvider = dataProtectionProvider;
 }
Example #10
0
        public DistributedSessionStore(IDistributedCache cache, ILoggerFactory loggerFactory)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

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

            _cache = cache;
            _loggerFactory = loggerFactory;
        }
Example #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
            IDistributedCache cache)
        {
            var serverStartTimeString = DateTime.Now.ToString();
            byte[] val = Encoding.UTF8.GetBytes(serverStartTimeString);
            cache.Set("lastServerStartTime", val);
            
            app.UseStartTimeHeader();

            app.Run(async (context) =>
            {
                context.Response.ContentType = "text/html";
                await context.Response.WriteAsync("Hello World!");
            });
        }
        public JsonNavigationTreeBuilder(
            IHostingEnvironment appEnv,
            IOptions<NavigationOptions> navigationOptionsAccessor,
            ILoggerFactory loggerFactory,
            IDistributedCache cache)
        {
            if(appEnv == null) { throw new ArgumentNullException(nameof(appEnv)); }
            if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); }
            if (navigationOptionsAccessor == null) { throw new ArgumentNullException(nameof(navigationOptionsAccessor)); }

            this.appEnv = appEnv;
            navOptions = navigationOptionsAccessor.Value;
            logFactory = loggerFactory;
            log = loggerFactory.CreateLogger(typeof(JsonNavigationTreeBuilder).FullName);
            this.cache = cache;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SitemapService" /> class.
 /// </summary>
 /// <param name="cacheProfileSettings">The cache profile settings.</param>
 /// <param name="distributedCache">The distributed cache for the application.</param>
 /// <param name="logger">The <see cref="SitemapService"/> logger.</param>
 // $Start-ApplicationInsights$
 /// <param name="telemetryClient">The Azure Application Insights telemetry client.</param>
 // $End-ApplicationInsights$
 /// <param name="urlHelper">The URL helper.</param>
 public SitemapService(
     IOptions<CacheProfileSettings> cacheProfileSettings,
     IDistributedCache distributedCache,
     ILogger<SitemapService> logger,
     // $Start-ApplicationInsights$
     TelemetryClient telemetryClient,
     // $End-ApplicationInsights$
     IUrlHelper urlHelper)
 {
     CacheProfile cacheProfile = cacheProfileSettings.Value.CacheProfiles[CacheProfileName.SitemapNodes];
     this.cacheSlidingExpiration = TimeSpan.FromSeconds(cacheProfile.Duration.Value);
     this.distributedCache = distributedCache;
     this.logger = logger;
     // $Start-ApplicationInsights$
     this.telemetryClient = telemetryClient;
     // $End-ApplicationInsights$
     this.urlHelper = urlHelper;
 }
        /// <summary>
        /// Initializes a new instance of <see cref="Tailspin.Surveys.TokenStorage.DistributedTokenCache"/>
        /// </summary>
        /// <param name="claimsPrincipal">A <see cref="System.Security.Claims.ClaimsPrincipal"/> for the signed in user</param>
        /// <param name="distributedCache">An implementation of <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> in which to store the access tokens.</param>
        /// <param name="loggerFactory"><see cref="Microsoft.Extensions.Logging.ILoggerFactory"/> used to create type-specific <see cref="Microsoft.Extensions.Logging.ILogger"/> instances.</param>
        /// <param name="dataProtectionProvider">An <see cref="Microsoft.AspNet.DataProtection.IDataProtectionProvider"/> for creating a data protector.</param>
        public DistributedTokenCache(
            ClaimsPrincipal claimsPrincipal,
            IDistributedCache distributedCache,
            ILoggerFactory loggerFactory,
            IDataProtectionProvider dataProtectionProvider)
            : base()
        {
            Guard.ArgumentNotNull(claimsPrincipal, nameof(claimsPrincipal));
            Guard.ArgumentNotNull(distributedCache, nameof(distributedCache));
            Guard.ArgumentNotNull(loggerFactory, nameof(loggerFactory));
            Guard.ArgumentNotNull(dataProtectionProvider, nameof(dataProtectionProvider));

            _claimsPrincipal = claimsPrincipal;
            _cacheKey = BuildCacheKey(_claimsPrincipal);
            _distributedCache = distributedCache;
            _logger = loggerFactory.CreateLogger<DistributedTokenCache>();
            _protector = dataProtectionProvider.CreateProtector(typeof(DistributedTokenCache).FullName);
            AfterAccess = AfterAccessNotification;
            LoadFromCache();
        }
        public DistributedCacheNavigationTreeBuilder(
            INavigationTreeBuilder implementation,
            IDistributedCache cache,
            IOptions<DistributedCacheNavigationTreeBuilderOptions> optionsAccessor,
            INavigationCacheKeyResolver cacheKeyResolver,
            ILogger<DistributedCacheNavigationTreeBuilder> logger)
        {
            if (implementation == null) { throw new ArgumentNullException(nameof(implementation)); }
            if(implementation is DistributedCacheNavigationTreeBuilder) { throw new ArgumentException("implementation cannot be an instance of DistributedCacheNavigationTreeBuilder"); }
            if (cache == null) { throw new ArgumentNullException(nameof(cache)); }
            if (logger == null) { throw new ArgumentNullException(nameof(logger)); }
            if (optionsAccessor == null) { throw new ArgumentNullException(nameof(optionsAccessor)); }
            if (cacheKeyResolver == null) { throw new ArgumentNullException(nameof(cacheKeyResolver)); }

            this.implementation = implementation;
            this.cache = cache;
            log = logger;
            options = optionsAccessor.Value;
            this.cacheKeyResolver = cacheKeyResolver;

        }
Example #16
0
        public DistributedSession(
            IDistributedCache cache,
            string sessionId,
            TimeSpan idleTimeout,
            Func<bool> tryEstablishSession,
            ILoggerFactory loggerFactory,
            bool isNewSessionKey)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            if (string.IsNullOrEmpty(sessionId))
            {
                throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(sessionId));
            }

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

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

            _cache = cache;
            _sessionId = sessionId;
            _idleTimeout = idleTimeout;
            _tryEstablishSession = tryEstablishSession;
            _store = new Dictionary<EncodedKey, byte[]>();
            _logger = loggerFactory.CreateLogger<DistributedSession>();
            _isNewSessionKey = isNewSessionKey;
        }
Example #17
0
 public AccountController(SignInManager <User> signIn, IDistributedCache cache)
 {
     _signIn     = signIn;
     this._cache = cache;
 }
 public CustomerCacheReponsitory(IDistributedCache cache, IOptions <CustomerSettings> settings) : base(cache, KeyPrefix)
 {
     _setting = settings.Value;
 }
 public SqlCachingController(IDistributedCache distributedCache)
 {
     _memoryCache = distributedCache;
 }
 protected void Initialize(IDistributedCache distributedCache)
 {
     _distributedCache = distributedCache;
 }
Example #21
0
 public DistributedCacheFactory(IDistributedCache cache, ICacheSerializer serializer)
 {
     _cache      = Guard.ArgumentNotNull(cache, nameof(cache));
     _serializer = Guard.ArgumentNotNull(serializer, nameof(serializer));
 }
 public LoggedUsersDistributedStorage(IDistributedCache distributedCache, CacheKeyCreator cacheKeyCreator)
 {
     _distributedCache = distributedCache;
     _cacheKeyCreator  = cacheKeyCreator;
 }
 public CacheCaptchaStore(IDistributedCache <Captcha> cache)
 {
     Cache = cache;
 }
 public DistributedHttpCache(IDistributedCache cache) => _cache = cache;
Example #25
0
 public FeatureValueCacheItemInvalidator(IDistributedCache <FeatureValueCacheItem> cache)
 {
     Cache = cache;
 }
 public HomeController(IDistributedCache cache, IConnectionMultiplexer conn)
 {
     _cache = cache;
     _conn  = conn;
 }
Example #27
0
 public TestController(IDistributedCache cache)
 {
     this.cache = cache;
 }
 public CookieService(CookieContext context, IDistributedCache cache = null)
 {
     _context = context;
     _cache   = cache;
 }
Example #29
0
 public ScopedDistributedCache(IDistributedCache distributedCache)
 {
     _distributedCache = distributedCache;
 }
Example #30
0
 public CacheManager(IDistributedCache cache)
 {
     _cache  = cache;
     options = new DistributedCacheEntryOptions();
     options.SetAbsoluteExpiration(DateTimeOffset.UtcNow.AddMinutes(30));
 }
 // ReSharper disable once SuggestBaseTypeForParameter
 public Yandere(IYandereApi api, IDistributedCache cache) : base(api, _sourceBooru, cache)
 {
 }
Example #32
0
 public WaterTemperatureCache(IDistributedCache cache) : base(cache)
 {
 }
Example #33
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IApplicationLifetime appLifetime, IDistributedCache cache)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            loggerFactory.AddSerilog();
            Log.Logger = new LoggerConfiguration()
                         .WriteTo
                         .ApplicationInsightsTraces(Configuration["ApplicationInsights:InstrumentationKey"])
                         .CreateLogger();
            app.UseApplicationInsightsRequestTelemetry();
            appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);

            app.UseExceptionHandler(
                builder =>
            {
                builder.Run(context =>
                {
                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    context.Response.ContentType = "application/json";
                    return(Task.FromResult(0));
                }
                            );
            }
                );
            var jwtAppSettingOptions      = Configuration.GetSection(nameof(JwtIssuerOptions));
            var tokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer = true,
                ValidIssuer    = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)],

                ValidateAudience = true,
                ValidAudience    = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)],

                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = _key,

                RequireExpirationTime = false,
                ValidateLifetime      = false,

                ClockSkew = TimeSpan.Zero
            };

            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                AutomaticAuthenticate     = true,
                AutomaticChallenge        = true,
                TokenValidationParameters = tokenValidationParameters
            });
            app.UseSimpleInjectorAspNetRequestScoping(_container);

            _container.Options.DefaultScopedLifestyle = new AspNetRequestLifestyle();

            ConfigureCache(env);

            ConfigureAzureStorage(env);

            RegisterServices(app);

            ConfigureHash();

            InitializeContainer(app);

            RegisterDbContext <VotingContext>(Configuration.GetConnectionString("DefaultConnection"));

            RegisterAutomapper();

            BuildMediator();


            _container.Verify();

            app.UseMvc();

            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger();

            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUi();
        }
Example #34
0
 public RestoreCachedRequestParameters(IDistributedCache cache)
 => _cache = cache;
Example #35
0
 public StartTimeHeader(RequestDelegate next,
    IDistributedCache cache)
 {
     _next = next;
     _cache = cache;
 }
 /// <summary>
 /// Creates a new <see cref="DistributedCacheTagHelperStorage"/>.
 /// </summary>
 /// <param name="distributedCache">The <see cref="IDistributedCache"/> to use.</param>
 public DistributedCacheTagHelperStorage(IDistributedCache distributedCache)
 {
     _distributedCache = distributedCache;
 }
Example #37
0
 /// <summary>
 /// 初始化一个<see cref="OnlineUserProvider{TUser, TUserKey, TUserClaim, TUserClaimKey, TRole, TRoleKey}"/>类型的新实例
 /// </summary>
 public OnlineUserProvider(IServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider;
     _cache           = serviceProvider.GetService <IDistributedCache>();
 }
Example #38
0
 public UserController(DBContext context, IDistributedCache memoryCache)
 {
     _context     = context;
     _memoryCache = memoryCache;
 }
Example #39
0
 public ProjectQuery(IDatabaseSet databaseSet, IDistributedCache redisCache, IMapper mapper) : base(databaseSet, redisCache, mapper)
 {
 }
 public BookStoreController(IBookManager bookManager, IDistributedCache distributedCache, ILoggerFactory factory)
 {
     this.bookManager      = bookManager;
     this.distributedCache = distributedCache;
     this.logger           = factory.CreateLogger("BookCategory");
 }
 public static async Task<T> GetUsingBytesAsync<T>(this IDistributedCache distributedCache, string key, CancellationToken token = default(CancellationToken)) => (await distributedCache.GetAsync(key, token)).Get<T>();
 /// <summary>
 /// Constructor
 /// </summary>
 public ConsentPersonCache(IGdprCapability gdprCapability, IDistributedCache cache)
     : base(gdprCapability.PersonConsentService, cache)
 {
 }
 public static T GetUsingJson<T>(this IDistributedCache distributedCache) => distributedCache.GetUsingJson<T>(typeof(T).FullName);
 public HomeController(IDistributedCache cacheMechanism)
 {
     this.cacheMechanism = cacheMechanism;
 }
 public static T GetUsingJson<T>(this IDistributedCache distributedCache, string key) => JsonConvert.DeserializeObject<T>(distributedCache.GetString(key));
Example #46
0
 public BookService(IBookRepository repository, IDistributedCache distributedCache)
 {
     this.BookRepository   = repository;
     this.DistributedCache = distributedCache;
 }
Example #47
0
 public JobNameRepository(IDistributedCache distributedCache, IRepositoryAsync <JobName> repository)
 {
     _distributedCache = distributedCache;
     _repository       = repository;
 }
Example #48
0
 public DefaultDynamicCache(IDistributedCache distributedCache)
 {
     _distributedCache = distributedCache;
 }
Example #49
0
 public HomeController(ILogger <HomeController> logger, IDistributedCache distributedCache)
 {
     _logger = logger;
     cache   = distributedCache;
 }
Example #50
0
 public DataCategoriesAccessor(CommonDbContext _dbContext, IDistributedCache _DistributedCache)
     : base(_dbContext, _DistributedCache)
 {
     dbContext = _dbContext;
 }
 public static async Task<T> GetUsingBytesAsync<T>(this IDistributedCache distributedCache, CancellationToken token = default(CancellationToken)) => await distributedCache.GetUsingBytesAsync<T>(typeof(T).FullName, token);
 public DistributedSessionStore([NotNull] IDistributedCache cache, [NotNull] ILoggerFactory loggerFactory)
 {
     _cache = cache;
     _loggerFactory = loggerFactory;
 }
 public RedisCacheTagHelper(IDistributedCache redisCache)
 {
     _redisCache = redisCache;
 }
Example #54
-2
 public CacheContext()
 {
     Local = A.Fake<ILocalCache>();
     Distributed = A.Fake<IDistributedCache>();
     LocalCache.StaticProvider = Local;
     DistributedCache.StaticProvider = Distributed;
 }