public async Task <IEnumerable <SelectListItem> > GetTypes(CancellationToken cancelattionToken = default(CancellationToken)) { return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateTypesCacheKey(), async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetTypes(cancelattionToken); })); }
public void Should_return_false_with_differe_etag() { var context = this.GetContext("moo", null); var result = CacheHelpers.ReturnNotModified(this.etag, this.lastModified, context); result.ShouldBeFalse(); }
public async Task <IEnumerable <SelectListItem> > GetMaterials() { return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateMaterialsCacheKey(), async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetMaterials(); })); }
public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied); _cache.Remove(cacheKey); CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied); }
public void Should_return_modified_false_if_no_etag_and_no_ifmodifiedsince_sent() { var context = this.GetContext(null, null); var result = CacheHelpers.ReturnNotModified(this.etag, this.lastModified, context); result.ShouldBeFalse(); }
public async Task <CatalogItemViewModel> GetItemById(int id, bool convertPrice = true, CancellationToken cancellationToken = default) { return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateCatalogItemIdKey(id), async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetItemById(id, convertPrice, cancellationToken); })); }
/// <summary> /// Get /// </summary> /// <returns></returns> public IEnumerable <ToDoItem> GetCachedToDoItems() { IEnumerable <ToDoItem> toDoItems; _cache.TryGetValue <IEnumerable <ToDoItem> >(CacheHelpers.GenerateToDoItemsCacheKey(), out toDoItems); return(toDoItems); }
public async Task <ActionResult <ArticleDetailsDto> > Get(long id) { var article = await HandleWithCache(new GetArticleQuery(id), CacheHelpers.GetArticleCacheKey(id)); await Handle(new AddArticleViewCommand(id)); return(Ok(article)); }
public void Should_return_true_with_same_etag() { var context = this.GetContext(this.etag, null); var result = CacheHelpers.ReturnNotModified(this.etag, this.lastModified, context); result.ShouldBeTrue(); }
public void Should_return_false_with_date_in_the_past() { var context = this.GetContext(null, this.lastModified.AddMinutes(-1)); var result = CacheHelpers.ReturnNotModified(this.etag, this.lastModified, context); result.ShouldBeFalse(); }
public void Should_return_true_with_date_in_future() { var context = this.GetContext(null, this.lastModified.AddHours(1)); var result = CacheHelpers.ReturnNotModified(this.etag, this.lastModified, context); result.ShouldBeTrue(); }
public async Task <CategoryViewModel> GetCategories() { return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateCategoriesCacheKey(), async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetCategories(); })); }
/// <summary> /// Set /// </summary> /// <param name="entry"></param> public void SetCachedToDoItems(IEnumerable <ToDoItem> entry) { // Set cache options var cacheEntryOptions = new MemoryCacheEntryOptions() // Keep in cache for this time, reset time if accessed. .SetSlidingExpiration(TimeSpan.FromDays(1)); _cache.Set(CacheHelpers.GenerateToDoItemsCacheKey(), entry, cacheEntryOptions); }
private async void Submit_ClickAsync(object sender, RoutedEventArgs e) { var value = JsonHelper.ToJson(forCache.Where(i => i.Selected == true).Select(i => i.Token).ToList()); await CacheHelpers.SaveSpecificCacheValueAsync(CacheSelect.MetroList, value); SetMetroList(value); InnerContentPanel.IsOpen = false; InitContentResourcesAsync(); }
public void ReturnsCatalogItemCacheKey() { var pageIndex = 0; int?brandId = null; int?typeId = null; var result = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, 10, brandId, typeId); Assert.Equal("items-0-10--", result); }
/// <summary> /// Creates an EmbeddedResponse /// </summary> /// <param name="assembly">The assembly containing the embedded file with which to respond</param> /// <param name="resourcePath">The path to the embedded resource</param> /// <param name="name">The name of the resource</param> /// <param name="lastModifiedDate">The date that will be compared against modified headers to determine if a NotModified response should be sent</param> /// <param name="context">The Nancy context</param> public EmbeddedResponse(Assembly assembly, string resourcePath, string name, DateTime lastModifiedDate, NancyContext context = null) { this.lastModifiedDate = lastModifiedDate; this.ContentType = MimeTypes.GetMimeType(name); this.StatusCode = HttpStatusCode.OK; var content = GetResourceContent(assembly, resourcePath, name); if (content != null) { var etag = GenerateETag(content); if (CacheHelpers.ReturnNotModified(etag, lastModifiedDate, context)) { this.StatusCode = HttpStatusCode.NotModified; this.ContentType = null; this.Contents = Response.NoBody; } else { this.WithHeader("Last-Modified", this.lastModifiedDate.ToString("R")); this.WithHeader("ETag", etag); content.Seek(0, SeekOrigin.Begin); if (context.Request.Headers.AcceptEncoding.Contains("gzip")) { this.WithHeader("Content-Encoding", "gzip"); } this.Contents = stream => { if (content != null) { if (context.Request.Headers.AcceptEncoding.Contains("gzip")) { using (GZipStream zs = new GZipStream(stream, CompressionMode.Compress, true)) { content.CopyTo(zs); } } else { content.CopyTo(stream); } } else { stream.Write(ErrorText, 0, ErrorText.Length); } }; } } else { } }
public async Task <object> GetCostVsSavings() { var cacheKey = CacheHelpers.GenerateCacheKeyForCostRecommendationSaving(); return(await cache.GetOrCreateAsync(cacheKey, async entry => { entry.AbsoluteExpirationRelativeToNow = CacheHelpers.absoluteExpirationRelativeToNow; return await costRecommendationsOperations.GetCostVsSavings(); })); }
public void GetTaxonomyKey_WithDifferentValues_AreUnique() { var keys = new[] { CacheHelpers.GetTaxonomyKey("codename"), CacheHelpers.GetTaxonomyKey("other_codename") }; keys.Distinct().Count().Should().Be(keys.Length); }
public async Task <IEnumerable <SelectListItem> > GetBrands() { var cachedKey = CacheHelpers.GenerateCatalogBrandCacheKey(); return(await _cache.GetOrCreateAsync(cachedKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetBrands(); })); }
public async Task <CostRecommendationSummaryResponse> GetCostSummary() { var cacheKey = CacheHelpers.GenerateCacheKeyForCostRecommnedationSummary(); return(await cache.GetOrCreateAsync(cacheKey, async entry => { entry.AbsoluteExpirationRelativeToNow = CacheHelpers.absoluteExpirationRelativeToNow; return await costRecommendationsOperations.GetCostSummary(); })); }
public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, string searchText, int?brandId, int?typeId, bool convertPrice = true, CancellationToken cancellationToken = default(CancellationToken)) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, Constants.ITEMS_PER_PAGE, searchText, brandId, typeId, CultureInfo.CurrentCulture.Name); return(await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, searchText, brandId, typeId, convertPrice, cancellationToken); })); }
public ActionResult DeleteConfirmed(int id) { Category category = categoryManager.Find(x => x.ID == id); categoryManager.Delete(category); CacheHelpers.ClearCache("categories-cache"); return(RedirectToAction("Index")); }
public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId, int?materialId) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, Constants.ITEMS_PER_PAGE, brandId, typeId, materialId); return(await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId, materialId); })); }
public async Task <List <CostUsageResponse> > GetLinkedAccounts() { var cacheKey = CacheHelpers.GenerateCacheKeyForLinkedAccount(DateTime.Now.AddDays(-30).ToString("yyyy-mm-dd"), DateTime.Now.ToString("yyyy-mm-dd")); return(await cache.GetOrCreateAsync(cacheKey, async entry => { entry.AbsoluteExpirationRelativeToNow = CacheHelpers.absoluteExpirationRelativeToNow; return await costExplorerOperations.GetLinkedAccounts(); })); }
public async Task <List <CostUsageResponse> > GetCostByMonth(CostUsageRequest costUsageRequest) { var cacheKey = CacheHelpers.GenerateCostByMonthCacheItemKey(costUsageRequest); return(await cache.GetOrCreateAsync(cacheKey, async entry => { entry.AbsoluteExpirationRelativeToNow = CacheHelpers.absoluteExpirationRelativeToNow; return await costExplorerOperations.GetCostByMonth(costUsageRequest); })); }
internal static IEnhancedOrgService GetConnection(string connectionString, bool noCache = false) { if (noCache) { ResetCache(connectionString); } var memKey = $"{ConnCacheMemKey}_{connectionString}"; lock (lockObj) { try { var service = CacheHelpers.GetFromMemCache <IEnhancedOrgService>(memKey); if (service != null) { return(service); } Status.Update($"Creating connection to CRM ... "); Status.Update($"Connection String:" + $" '{CrmHelpers.SecureConnectionString(connectionString)}'."); service = EnhancedServiceHelper.GetCachingPoolingService( new ServiceParams { ConnectionParams = new ConnectionParams { ConnectionString = connectionString }, PoolParams = new PoolParams { PoolSize = 5, DequeueTimeout = TimeSpan.FromSeconds(20) }, CachingParams = new CachingParams { CacheScope = CacheScope.Service }, OperationHistoryLimit = 1 }); CacheHelpers.AddToMemCache(memKey, service, TimeSpan.MaxValue); Status.Update($"Created connection."); return(service); } catch { CacheHelpers.RemoveFromMemCache(memKey); throw; } } }
protected override async ValueTask <DiscordChannelPacket> GetFromCacheAsync(params object[] id) { if (id.Length == 1) { return(await cacheClient.HashGetAsync <DiscordChannelPacket>( CacheHelpers.ChannelsKey(), id[0].ToString())); } return(await cacheClient.HashGetAsync <DiscordChannelPacket>( CacheHelpers.ChannelsKey((ulong)id[1]), id[0].ToString())); }
public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId) { var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, itemsPage, brandId, typeId); return(await _cache.GetOrCreateAsync(cacheKey, async entry => { entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration; // calling second class's GetCatalogItems from this class's GetCatalogItems() because only the second class contains the business logic return await _catalogViewModelService.GetCatalogItems(pageIndex, itemsPage, brandId, typeId); })); }
public void GetContentElementKey_WithDifferentValues_AreUnique() { var keys = new[] { CacheHelpers.GetContentElementKey("type_codename", "element_codename"), CacheHelpers.GetContentElementKey("type_codename", "other_element_codename"), CacheHelpers.GetContentElementKey("other_type_codename", "element_codename") }; keys.Distinct().Count().Should().Be(keys.Length); }
public void GenerateCatalogItemCacheKey_ShouldReturn_ValidData() { var pageIndex = 100; var itemsPage = 11; var brandId = 55; var typeId = 1; var result = CacheHelpers.GenerateCatalogItemCacheKey(pageIndex, itemsPage, brandId, typeId); result.Should().Be("items-100-11-55-1"); }