locked
Grab Collection from Cache RRS feed

  • Question

  • User-2089506584 posted

    How to grab items from cache collection?

    The query below retrieves the CustomerId and NumOrders from the Order entity and pass the result at Cache_Individual_Orders_Items function which iterates the collection and put the individual items in cache having a prefix of "Order:CustomerId:".

    After I put the items in cache how to grab the individual items having NumOrders value of more than 100+ from cache?

    public CustOrderList() {
    
       var ordersList = from p in dbNOrthwind.Orders
                               select new {
                                                CustomerId = p.CustomerId, 
    					    ProductId = p.ProductId, 
    					    NumOrders = p.OrderDetails.Count 
    					 }
    
       Cache_Individual_Orders_Items(ordersList); //put items in cache
    }
    
    public void Cache_Individual_Orders_Items(IList<Order> ordersList)
    {
       Cache cache = HttpRuntime.Cache;
       DateTime absolutionExpiration = Cache.NoAbsoluteExpiration;
       TimeSpan slidingExpiration = Cache.NoSlidingExpiration;
    
       foreach (Order order in ordersList)
       {
          string key = "Order:CustomerId:" + order.CustomerId + ":ProductId" + order.ProductId;
    
          cache.Add(key, order, absolutionExpiration, slidingExpiration, priority);
       }
    }



    Thank You,

    -imperialx

    Sunday, July 15, 2012 6:43 AM

Answers

  • User1943143334 posted

    Hi,

    First you have to retrieve all the records stored in the Cache. Once it's done, you may have to retrieve all the records which has NumOrders more than 100, by using LINQ query etc.,

    Hope it helps u...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2012 5:47 AM

All replies

  • User-661350001 posted

    basically you have use Dictionary and have a key concatination CustomerID_ProductID_NumOrders and check if already contail the key if not then query and cache and return from cache

    Sunday, July 15, 2012 7:09 AM
  • User-2089506584 posted

    have a key concatination CustomerID_ProductID_NumOrders

    What if I change the key to this

    string key = "Order:CustomerId:" + order.CustomerId

    It only has the CustomerID. How can I still get the NumOrders from the dictionary?

    Sunday, July 15, 2012 7:46 AM
  • User1943143334 posted

    Hi,

    First you have to retrieve all the records stored in the Cache. Once it's done, you may have to retrieve all the records which has NumOrders more than 100, by using LINQ query etc.,

    Hope it helps u...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2012 5:47 AM