public async Task Put(ICacheContext context, CacheEntry newCacheEntry) { var key = await GetKey(context); var isResponseMessage = false; CacheEntry cacheEntry = null; var temp = await _cache.Get <CacheEntry>(key); if (temp != null && context.ResponseValidator(context, temp.Metadata) == ResponseValidationResult.OK) { cacheEntry = temp; } var response = newCacheEntry.Value as HttpResponseMessage; if (cacheEntry == null) { object value; if (response != null) { value = await _serializer.Serialize(response, context.Token); isResponseMessage = true; } else { value = newCacheEntry.Value; } cacheEntry = new CacheEntry(newCacheEntry.Metadata) { Value = value, IsHttpResponseMessage = isResponseMessage }; } else { cacheEntry.Metadata.Merge(newCacheEntry.Metadata); } await Task.WhenAll( _cache.Put(key, cacheEntry), _varyBy.Put(context.Uri, newCacheEntry.Metadata.VaryHeaders), _uriInfo.Put(context.Uri, key) ); }
public bool TryFindMatchingMember( string destinationName, IModelValueMemberInfo destinationMemberInfo, ICacheContext <string, IModelValueMemberInfo> sourceMemberInfos, out string sourceMemberName, out IModelValueMemberInfo sourceMemberInfo) { if (sourceMemberInfos.TryGetValue(destinationName, out sourceMemberInfo)) { sourceMemberName = sourceMemberInfo.Name; return(true); } sourceMemberName = default; sourceMemberInfo = default; return(false); }
public async Task <Modifiable> OnStore(ICacheContext context, object result) { CacheStoreContext handlerContext = null; foreach (var handlerInfo in GetHandlerInfo(CacheHandlerType.Store)) { if (handlerContext == null) { handlerContext = ((Func <ICacheContext, object, CacheStoreContext>)handlerInfo.InitialConstructor)(context, result); } else { handlerContext = ((Func <CacheStoreContext, CacheStoreContext>)handlerInfo.ContinuationConstructor)(handlerContext); } await handlerInfo.Handler(handlerContext); } return((handlerContext ?? new CacheStoreContext <object>(context, null)).GetHandlerResult()); }
public async Task <Modifiable> OnExpiring(ICacheContext context, RequestValidationResult reason) { CacheExpiringContext handlerContext = null; foreach (var handlerInfo in GetHandlerInfo(CacheHandlerType.Expiring)) { if (handlerContext == null) { handlerContext = ((Func <ICacheContext, RequestValidationResult, CacheExpiringContext>)handlerInfo.InitialConstructor)(context, reason); } else { handlerContext = ((Func <CacheExpiringContext, CacheExpiringContext>)handlerInfo.ContinuationConstructor)(handlerContext); } await handlerInfo.Handler(handlerContext); } return((handlerContext ?? new CacheExpiringContext(context, 0)).GetHandlerResult()); }
public async Task <Modifiable> OnExpired(ICacheContext context, RequestValidationResult reason, IReadOnlyCollection <Uri> expiredUris) { CacheExpiredContext handlerContext = null; foreach (var handlerInfo in GetHandlerInfo(CacheHandlerType.Expired)) { if (handlerContext == null) { handlerContext = ((Func <ICacheContext, RequestValidationResult, IReadOnlyCollection <Uri>, CacheExpiredContext>)handlerInfo.InitialConstructor)(context, reason, expiredUris); } else { handlerContext = ((Func <CacheExpiredContext, CacheExpiredContext>)handlerInfo.ContinuationConstructor)(handlerContext); } await handlerInfo.Handler(handlerContext); } return((handlerContext ?? new CacheExpiredContext(context, 0, null)).GetHandlerResult()); }
private async Task ExpireResult(ICacheContext context, RequestValidationResult reason) { if (!Enabled) { return; } if ((context.Items["CacheHandler_ItemExpired"] as bool?).GetValueOrDefault()) { return; } var expiringResult = await context.HandlerRegister.OnExpiring(context, reason); var uris = await _cacheManager.Delete(context, expiringResult.Value as IEnumerable <Uri>); await context.HandlerRegister.OnExpired(context, reason, new ReadOnlyCollection <Uri>(uris)); context.Items["CacheHandler_ItemExpired"] = true; }
private CacheEntry <TResult> CreateEntry(TKey k, Func <ICacheContext <TKey>, TResult> context) { var entry = new CacheEntry <TResult>(); var currentContext = new DefaultCacheContext <TKey>(k, entry.AddToken); ICacheContext parentContext = null; try { parentContext = cacheContextAccessor.Current; cacheContextAccessor.Current = currentContext; entry.Result = context(currentContext); } finally { cacheContextAccessor.Current = parentContext; } entry.CompactTokens(); return(entry); }
public static RequestValidationResult CanCacheRequest(ICacheContext context) { if (context.Uri == null) { return(RequestValidationResult.NoRequestInfo); } var validation = CanCacheRequest(context.Request, context.CacheableHttpMethods); if (validation != RequestValidationResult.OK) { return(validation); } if (typeof(IEmptyResult).IsAssignableFrom(context.ResultType)) { return(RequestValidationResult.ResultIsEmpty); } return(RequestValidationResult.OK); }
public async Task <CacheEntry> Get(ICacheContext context) { var key = await GetKey(context); var cacheEntry = await _cache.Get <CacheEntry>(key); if (cacheEntry == null) { return(CacheEntry.Empty); } var validation = context.ResponseValidator(context, cacheEntry.Metadata); if (validation == ResponseValidationResult.Stale && !context.AllowStaleResultValidator(context, cacheEntry.Metadata)) { return(CacheEntry.Empty); } if (validation != ResponseValidationResult.OK && validation != ResponseValidationResult.Stale && validation != ResponseValidationResult.MustRevalidate) { return(CacheEntry.Empty); } object result; if (cacheEntry.IsHttpResponseMessage) { var responseBuffer = cacheEntry.Value as byte[]; result = await _serializer.Deserialize(responseBuffer, context.Token); } else { result = cacheEntry.Value; } return(new CacheEntry(result, cacheEntry.Metadata)); }
public async Task <IList <Uri> > Delete(ICacheContext context, IEnumerable <Uri> additionalDependentUris) { var key = await GetKey(context); var uris = new List <Uri>(); if (key == CacheKey.Empty) { return(uris); } var cacheEntry = await _cache.Get <CacheEntry>(key); if (cacheEntry == null) { return(uris); } var deleteTask = _cache.Delete(key); var deleteUriTask = _uriInfo.DeleteKey(context.Uri, key); await Task.WhenAll(deleteTask, deleteUriTask); if (!deleteTask.Result) { return(uris); } if (context.Uri != null) { uris.Add(context.Uri); } var relatedUris = await DeleteDependentUris(cacheEntry, context, additionalDependentUris); uris.AddRange(relatedUris); return(uris); }
private void StartConfig(ClientConfig clientConfig) { _clientConfig = clientConfig; _restContext = clientConfig.GetRest(); _restContext.Init(); _cacheContext = clientConfig.CacheContext; _serializerOptions = new JsonSerializerOptions() { Converters = { new MemberCollectionConverter(_cacheContext, this, Logger), new UserCollectionConverter(_cacheContext, this, Logger), new ChannelCollectionConverter(_cacheContext, this, _restContext,Logger), new ChannelConverter(_cacheContext, _restContext, Logger), new ULongConverter(), new TimeSpanConverter() } }; _gatewayContext = clientConfig.GetGateway(); Logger = clientConfig.Logger; Logger.Log(LoggingLevel.Dcs, "DiscosCs v0.1-dev"); InitCollections(); }
public AccountController(ICacheContext cacheContext, IUserService userService) : base(cacheContext, userService) { }
public LoginParse(AppInfoService infoService, ICacheContext cacheContext, IRepository <User> userApp) { _appInfoService = infoService; _cacheContext = cacheContext; _app = userApp; }
public LoginService(ICacheContext cacheContext, IHttpContextAccessor httpContextAccessor) { _cacheContext = cacheContext; _httpContextAccessor = httpContextAccessor; }
public CheckController(AuthContextFactory app, LoginParse loginParse, ICacheContext cacheContext) { _app = app; _loginParse = loginParse; _cacheContext = cacheContext; }
public MedicineController(ICacheContext cacheContext, IUserService userService, IMedicineService medicineService) : base(cacheContext, userService) { _medicineService = medicineService; }
public DictController(WholeInjection injection, ICacheContext cacheContext) { _cacheContext = cacheContext; this.injection = injection; }
public Handler(ICacheContext cacheContext, IHttpContextAccessor httpContextAccessor) { this.cacheContext = cacheContext; this.httpContext = httpContextAccessor.HttpContext; }
private Task <CacheKey> GetKey(ICacheContext context) { return(GetKey(context.ResultType, context.Uri, context.DefaultVaryByHeaders, context.Request?.Headers)); }
public PurchaseController(ICacheContext cacheContext, IUserService userService) : base(cacheContext, userService) { }
public ChannelConverter(ICacheContext cacheContext, IRestContext restContext, ILogger logger) { _cacheContext = cacheContext; _restContext = restContext; _logger = logger; }
protected ControllerBase(ICacheClient cache) : this() { Cache = cache; CacheContext = new CacheContext(Cache); }
public UserManagerController(ICacheContext cacheContext, IUserService userService) : base(cacheContext, userService) { }
/// <summary> /// Gets the context. /// </summary> /// <returns>ICacheContext.</returns> public static ICacheContext GetContext() { return _cacheContext ?? (_cacheContext = new CacheContext()); }
public Task <bool> Contains <T>(string key, ICacheContext context) where T : class { return(ContainsWithContext <T>(key, context as TCacheContext)); }
public void Set <T>(string key, T value, ICacheContext context) where T : class { SetWithContext(key, value, context as TCacheContext); }
public Task <T> Get <T>(string key, ICacheContext context) where T : class { return(GetWithContext <T>(key, context as TCacheContext)); }
public UserCollectionConverter(ICacheContext cacheContext, IDatas datas, ILogger logger) { _cacheContext = cacheContext; _datas = datas; _logger = logger; }
public CacheHitContext(ICacheContext context, TResult result) : base(context, result) { }
public CacheContext(ICacheContext context) : this(context, context.GetHandlerContext()) { }
public RedisCacheService(ICacheContext context) { _context = context; }