public EntryController(IEntryRepository repository, IPodcastRepository podcastRepository, IUnitOfWork unitOfWork, IMapper mapper, IOptions <StorageSettings> storageSettings, IOptions <AppSettings> appSettings, IOptions <AudioFileStorageSettings> audioFileStorageSettings, IYouTubeParser youTubeParser, IConfiguration options, IResponseCacheService cache, IUrlProcessService processor, EntryPreProcessor preProcessor, ILogger <EntryController> logger, UserManager <ApplicationUser> userManager, IHttpContextAccessor contextAccessor) : base(contextAccessor, userManager, logger) { _podcastRepository = podcastRepository; _repository = repository; _options = options; _appSettings = appSettings.Value; _storageSettings = storageSettings.Value; _unitOfWork = unitOfWork; _audioFileStorageSettings = audioFileStorageSettings.Value; _mapper = mapper; _cache = cache; _youTubeParser = youTubeParser; _processor = processor; _preProcessor = preProcessor; }
/// <summary>Seta um objeto do tipo TResult, onde o nome da chave é o seu Nome completo do tipo</summary> /// <typeparam name="TValue">O tipo do objeto a ser inserido</typeparam> /// <param name="cacheService">Serviço de cache</param> /// <param name="objectValue">O valor do objeto a ser inserido na cache</param> /// <param name="timeTimeLive">Tempo de expiração do objeto</param> public static Task <bool> SetCacheResponseAsync <TValue>( this IResponseCacheService cacheService, TValue objectValue, TimeSpan?timeTimeLive ) => cacheService .SetCacheResponseAsync(typeof(TValue).FullName, objectValue, timeTimeLive);
public HomeController(IOptions <AppSettings> appSettings, ILogger <HomeController> logger, IPlayerService playerService, IDataProvider dataProvider, IResponseCacheService cache) { _playerService = playerService ?? throw new ArgumentNullException(nameof(playerService)); _dataProvider = dataProvider ?? throw new ArgumentNullException(nameof(dataProvider)); _cache = cache; _logger = logger; _appSettings = appSettings; }
public PodNomsDbContext( DbContextOptions <PodNomsDbContext> options, EntitySignalDataProcess entitySignalDataProcess, IResponseCacheService cache) : base(options, entitySignalDataProcess) { Database.SetCommandTimeout(360); _cache = cache; }
public CachedAttribute( IResponseCacheService responseCacheService, int timeToLiveSeconds = TimeToLiveForThreeDays ) { _timeToLiveSeconds = timeToLiveSeconds; ResponseCacheService = responseCacheService; }
public CurrExService(IResponseCacheService responseCacheService, IHttpContextAccessor httpContextAccessor) { _responseCacheService = responseCacheService; _httpContextAccessor = httpContextAccessor; var context = _httpContextAccessor.HttpContext; _cacheKey = Utility.Utility.GenerateCacheKeyFromRequest(context.Request); }
public CachedRemoveByConfigurationAttribute( IResponseCacheService responseCacheService, IOptionsMonitor <FilterCachedConfiguration> configuration ) { var configValues = configuration.CurrentValue; _removeCacheRoutes = configValues.CachedRemoveRoutes; ResponseCacheService = responseCacheService; }
public DataProviderImpl(IResponseCacheService iResponseCacheService, IConfiguration config, IMapper mapper) { _iResponseCacheService = iResponseCacheService; _config = config; _mapper = mapper; _tempDictionary = new Dictionary <string, bool>(); // data endpoint _dataUrl = _config["DataUrl"]; }
/// <summary>Obtém o valor de uma cache a partir da chave indicada</summary> /// <typeparam name="TValue">O tipo do objeto a ser inserido</typeparam> /// <param name="cacheService">Serviço de cache</param> public static Task <TValue> GetCachedResponseAsync <TValue>(this IResponseCacheService cacheService) where TValue : class => cacheService .GetCachedResponseAsStringAsync(typeof(TValue).FullName) .ContinueWith(o => { if (string.IsNullOrWhiteSpace(o.Result)) { return(null); } return(JsonSerializer.Deserialize <TValue>(o.Result)); });
public CachedByConfigurationAttribute( IResponseCacheService responseCacheService, IOptionsMonitor <FilterCachedConfiguration> configuration, int timeToLiveSeconds = TimeToLiveForThreeDays ) { var configValues = configuration.CurrentValue; _timeToLiveSeconds = configValues.GeneralTimeToLiveSeconds ?? timeToLiveSeconds; _cachedRoutes = configValues.CachedRoutes; ResponseCacheService = responseCacheService; }
public OTPLoginCommandHandler( IIdentityRepoService identityRepoService, UserManager <cor_useraccount> userManager, IMeasureService measure, IResponseCacheService cacheService, DataContext dataContext) { _dataContext = dataContext; _userManager = userManager; _service = identityRepoService; _measure = measure; _cacheService = cacheService; }
/// <summary> /// Initializes a new instance. /// </summary> public ResponseCacheHttpMiddleware( FluentHttpMiddlewareDelegate next, FluentHttpMiddlewareClientContext context, ResponseCacheHttpMiddlewareOptions options, ILoggerFactory loggerFactory, IResponseCacheService service ) { _next = next; _options = options; _logger = loggerFactory.CreateLogger($"{typeof(ResponseCacheHttpMiddleware).Namespace}.{context.Identifier}.ResponseCache"); _service = service; }
public UserService(IUserRepository repository , IMapper mapper , ITokenManager tokenManager , IConfiguration configuration , IMqServices mqServices , IResponseCacheService caching) { _repository = repository; _mapper = mapper; _tokenManager = tokenManager; _configuration = configuration; _mqServices = mqServices; _caching = caching; }
public async override Task Invoke(AspectContext context, AspectDelegate next) { var cachedRemoveConfigurationProvider = context.ServiceProvider.GetService <IOptionsMonitor <FilterCachedConfiguration> >(); var configCacheRemove = context.GetCacheRemoveConfigurationByMethodName(cachedRemoveConfigurationProvider.CurrentValue); if (configCacheRemove != null) { ResponseCacheService = context.ServiceProvider.GetService <IResponseCacheService>(); await ResponseCacheService .RemoveCachedResponseByNamesAsync(configCacheRemove.PatternMethodCachedName); } await next(context); }
public async override Task Invoke(AspectContext context, AspectDelegate next) { if (context.HasAttributeType(GetType())) { await next(context); return; } await next(context); ResponseCacheService = context.ServiceProvider.GetService <IResponseCacheService>(); await ResponseCacheService .RemoveAllByPatternAsync(RemovePattern); }
/// <summary>Obtém o valor de uma cache a partir da chave indicada</summary> /// <param name="cacheService">Serviço de cache</param> /// <param name="cacheKey">Nome da chave de cache</param> /// <param name="returnType">Tipo de retorno</param> public static Task <object> GetCachedResponseAsync( this IResponseCacheService cacheService, string cacheKey, Type returnType ) => cacheService .GetCachedResponseAsStringAsync(cacheKey) .ContinueWith(o => { if (string.IsNullOrWhiteSpace(o.Result)) { return(null); } return(JsonSerializer.Deserialize(o.Result, returnType)); });
/// <summary>Seta um objeto do tipo TResult, onde o nome da chave é o seu Nome completo do tipo</summary> /// <typeparam name="TValue">O tipo do objeto a ser inserido</typeparam> /// <param name="cacheService">Serviço de cache</param> /// <param name="cacheKey">Nome da chave de cache</param> /// <param name="objectValue">O valor do objeto a ser inserido na cache</param> /// <param name="timeTimeLive">Tempo de expiração do objeto</param> public static Task <bool> SetCacheResponseAsync <TValue>( this IResponseCacheService cacheService, string cacheKey, TValue objectValue, TimeSpan?timeTimeLive ) { if (objectValue == null) { return(Task.FromResult(false)); } return(cacheService .SetCacheResponseAsync(cacheKey, JsonSerializer.Serialize(objectValue), timeTimeLive)); }
public LoginCommandHandler( IIdentityRepoService identityRepoService, UserManager <cor_useraccount> userManager, IMeasureService measure, DataContext dataContext, IDetectionService detectionService, ILoggerService loggerService, IResponseCacheService responseCacheService) { _userManager = userManager; _cacheService = responseCacheService; _service = identityRepoService; _measure = measure; _securityContext = dataContext; _logger = loggerService; _detectionService = detectionService; }
public ProcessNewEntryJob( ILogger <ProcessNewEntryJob> logger, IConfiguration options, IEntryRepository entryRepository, IOptions <AppSettings> appSettings, IResponseCacheService cache, CachedAudioRetrievalService audioRetriever, IUnitOfWork unitOfWork) : base(logger) { _options = options; _entryRepository = entryRepository; _cache = cache; _audioRetriever = audioRetriever; _unitOfWork = unitOfWork; _logger = logger; _appSettings = appSettings.Value; }
public async override Task Invoke(AspectContext context, AspectDelegate next) { var cachedConfigurationProvider = context.ServiceProvider.GetService <IOptionsMonitor <FilterCachedConfiguration> >(); var configCache = context.GetCacheConfigurationByMethodName(cachedConfigurationProvider.CurrentValue); var methodReturnType = context.ProxyMethod.ReturnType; if ( configCache == null || methodReturnType == typeof(void) || methodReturnType == typeof(Task) || methodReturnType == typeof(ValueTask) ) { await next(context); return; } if (string.IsNullOrWhiteSpace(CacheName)) { CacheName = context.GetGenerateKeyByMethodNameAndValues(); } ResponseCacheService = context.ServiceProvider.GetService <IResponseCacheService>(); var returnType = context.IsAsync() ? methodReturnType.GenericTypeArguments.FirstOrDefault() : methodReturnType; var cachedValue = await ResponseCacheService.GetCachedResponseAsync(CacheName, returnType); if (cachedValue != null) { context.SetReturnType(methodReturnType, cachedValue); return; } await next(context); await ResponseCacheService .SetCacheResponseAsync( CacheName, await context.GetReturnValueAsync(), TimeSpan.FromSeconds(configCache.TimeToLiveSeconds ?? TimeToLiveSeconds) ); }
public MeasureService( IHttpContextAccessor accessor, DataContext dataContext, IEmailService service, IWebHostEnvironment webHostEnvironment, IBaseURIs uRIs, IDetectionService detectionService, IResponseCacheService cacheService, ILoggerService logger, UserManager <cor_useraccount> userManager) { _accessor = accessor; _mailservice = service; _security = dataContext; _env = webHostEnvironment; _logger = logger; _uRIs = uRIs; _cacheService = cacheService; _userManager = userManager; _detectionService = detectionService; }
public MakeAuthSettup(DataContext security, IResponseCacheService cacheService) { _security = security; _cacheService = cacheService; }
public AddContactCommandHandler(IResponseCacheService responseCacheService) { _responseCacheService = responseCacheService; }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var response = new MiddlewareResponse { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; using (var scope = context.HttpContext.RequestServices.CreateScope()) { try { IServiceProvider scopedServices = scope.ServiceProvider; RedisCacheSettings redisSettings = scopedServices.GetRequiredService <RedisCacheSettings>(); if (!redisSettings.Enabled) { await next(); return; } DataContext _dataContext = scopedServices.GetRequiredService <DataContext>(); IResponseCacheService responseCacheService = scopedServices.GetRequiredService <IResponseCacheService>(); var cacheKey = Cache.GenerateCacheKeyFromRequest(context.HttpContext.Request); if (context.HttpContext.Request.Method != "GET") { await responseCacheService.ResetCacheAsync(cacheKey); } var cachedResponse = await responseCacheService.GetCacheResponseAsync(cacheKey); if (!string.IsNullOrEmpty(cachedResponse)) { var contentResult = new ContentResult { Content = cachedResponse, ContentType = "application/json", StatusCode = 200 }; context.Result = contentResult; return; } var executedContext = await next(); if (executedContext.Result is OkObjectResult okObjectResult) { await responseCacheService.CatcheResponseAsync(cacheKey, okObjectResult, TimeSpan.FromSeconds(1000)); context.HttpContext.Response.StatusCode = 200; context.Result = new OkObjectResult(okObjectResult); return; } await next(); } catch (Exception ex) { context.HttpContext.Response.StatusCode = 500; response.Status.IsSuccessful = false; response.Status.Message.FriendlyMessage = ex.Message; response.Status.Message.TechnicalMessage = ex.ToString(); context.Result = new InternalServerErrorObjectResult(response); return; } } }
public GetUserQueryHandler(IMapper mapper, IResponseCacheService responseCacheService) { _mapper = mapper; _responseCacheService = responseCacheService; }
public CacheRepository(IResponseCacheService service) { _service = service; }
public AddUserCommandHandler(IResponseCacheService responseCacheService) { _responseCacheService = responseCacheService; }
private async Task GetOrCacheResponse(ActionExecutingContext context, ActionExecutionDelegate next, ILogger <CachedAttribute> logger, IResponseCacheService cacheService, string cacheKey) { if (!HttpMethods.IsGet(context.HttpContext.Request.Method)) { await next(); return; } var cachedResponse = await cacheService.GetCachedResponseAsync(cacheKey); if (!string.IsNullOrEmpty(cachedResponse)) { logger.LogInformation("Returing cached request for {CacheKey}", cacheKey); var contentResult = new ContentResult { Content = cachedResponse, ContentType = "application/json", StatusCode = 200 }; context.Result = contentResult; return; } logger.LogInformation("Response was not in Redis Cache!"); var result = await next(); if (result.Result is OkObjectResult okObjectResult) { logger.LogInformation("Caching request {CacheKey} for {Seconds} seconds in Redis", cacheKey, ttlSeconds); await cacheService.CacheResponseAsync(cacheKey, okObjectResult.Value, TimeSpan.FromSeconds(ttlSeconds)); } }
public SearchService(DataContext dataContext, IResponseCacheService cacheService) { _dataContext = dataContext; _cacheService = cacheService; }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var isResponseCacheEnabled = false; try { var responseCacheSettings = context .HttpContext .RequestServices .GetRequiredService <RedisCacheSettings>(); isResponseCacheEnabled = responseCacheSettings.IsEnabled; } catch (Exception ex) { // Log //throw; } if (!isResponseCacheEnabled) { await next(); return; } IResponseCacheService responseCacheService = null; try { responseCacheService = context .HttpContext .RequestServices .GetRequiredService <IResponseCacheService>(); } catch (Exception ex) { // Log //throw; } var responseCacheKey = GenerateCacheKeyFromRequest(context.HttpContext.Request); var willUseCache = responseCacheService != null && responseCacheKey != null; try { if (willUseCache) { var cachedResponse = await responseCacheService .GetCachedResponseAsync(responseCacheKey); if (!string.IsNullOrEmpty(cachedResponse)) { var contentResult = new ContentResult { Content = JToken.Parse(cachedResponse).ToString(Formatting.Indented), ContentType = "application/json", StatusCode = 200 }; context.Result = contentResult; return; } } } catch (Exception ex) { // Log //throw; } var executedContext = await next(); if (willUseCache) { //if (executedContext.Result is OkObjectResult okObjectResult) if (executedContext.Result is ObjectResult okObjectResult) { await responseCacheService .CacheResponseAsync( responseCacheKey, okObjectResult.Value, TimeSpan.FromSeconds(_timeToLiveSeconds)); } } }