Exemplo n.º 1
0
 public IEnumerable <FeaturedMovies> GetFeaturedMovies()
 {
     return(_memoryCache.GetOrCreate(FeaturedTokenKey, (entry) =>
     {
         entry.SetOptions(new MemoryCacheEntryOptions()
                          .AddExpirationToken(_tokenProviderService.GetToken(FeaturedTokenKey)));
         return GetMovies().OrderBy(m => m.Rank).Take(2);
     }
                                     ));
 }
Exemplo n.º 2
0
        public IEnumerable <string> GetProductNames(string category)
        {
            IEnumerable <Product> products;
            var key = typeof(ProductsService).FullName;

            if (!_memoryCache.TryGetValue(key, out products))
            {
                var changeToken = _tokenProviderService.GetToken(key);
                products = _memoryCache.Set <IEnumerable <Product> >(
                    key,
                    _products[category],
                    new MemoryCacheEntryOptions().AddExpirationToken(changeToken));
            }

            return(products.Select(p => p.ProductName));
        }