예제 #1
0
 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);
     }));
 }
예제 #2
0
        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();
        }
예제 #3
0
 public async Task <IEnumerable <SelectListItem> > GetMaterials()
 {
     return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateMaterialsCacheKey(), async entry =>
     {
         entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
         return await _catalogViewModelService.GetMaterials();
     }));
 }
예제 #4
0
        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);
        }
예제 #5
0
        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();
        }
예제 #6
0
 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);
        }
예제 #8
0
        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));
        }
예제 #9
0
        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();
        }
예제 #10
0
        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();
        }
예제 #11
0
        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);
        }
예제 #14
0
        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);
        }
예제 #16
0
        /// <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
            {
            }
        }
예제 #17
0
        public async Task <object> GetCostVsSavings()
        {
            var cacheKey = CacheHelpers.GenerateCacheKeyForCostRecommendationSaving();

            return(await cache.GetOrCreateAsync(cacheKey, async entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = CacheHelpers.absoluteExpirationRelativeToNow;
                return await costRecommendationsOperations.GetCostVsSavings();
            }));
        }
예제 #18
0
        public void GetTaxonomyKey_WithDifferentValues_AreUnique()
        {
            var keys = new[]
            {
                CacheHelpers.GetTaxonomyKey("codename"),
                CacheHelpers.GetTaxonomyKey("other_codename")
            };

            keys.Distinct().Count().Should().Be(keys.Length);
        }
예제 #19
0
        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();
            }));
        }
예제 #20
0
        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"));
        }
예제 #23
0
        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);
            }));
        }
예제 #26
0
        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;
                }
            }
        }
예제 #27
0
        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()));
        }
예제 #28
0
        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);
            }));
        }
예제 #29
0
        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);
        }
예제 #30
0
        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");
        }