Note that there are some explanatory texts on larger screens.

plurals
  1. POMaintaing List<T> in cache like database
    primarykey
    data
    text
    <p>I have a requirement where in i need to maintain a list in memory.</p> <p>Eg - </p> <pre><code>list&lt;products&gt; </code></pre> <p>every user will run the application and add new product/update product/ remove product from the list and all the changes should be reflected on that list.</p> <p>I am trying to store the list in the objectcache.</p> <p>but when i run the application it creates products but the moment i run it second time the list is not in the cache. need a help.</p> <p>Following is the code - </p> <pre><code>public class ProductManagement { List&lt;Productlist&gt; _productList; ObjectCache cache= MemoryCache.Default; public int Createproduct(int id,string productname) { if (cache.Contains("Productlist")) { _productList = (List&lt;Productlist&gt;)cache.Get("Productlist"); } else { _productList = new List&lt;Productlist&gt;(); } Product pro = new Product(); pro.ID = id; pro.ProductName = productname; _productList.Add(pro); cache.AddOrGetExisting("Productlist", _productList, DateTime.MaxValue); return id; } public Product GetProductbyId(int id) { if (cache.Contains("Productlist")) { _productList = (List&lt;Productlist&gt;)cache.Get("Productlist"); } else { _productList = new List&lt;Productlist&gt;(); } var product = _productList.Single(i =&gt; i.ID == id); return product; } } </code></pre> <p>how i can make sure that the list is persistent even when the application is not running, can this be possible. also how to keep the cache alive and to retrieve the same cache next time.</p> <p>Many thanks for help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload