NCache 4.3 - Online Documentation

Finding Items

 
Items can be retrieved from the cache either by using a Get method or the cache indexer. Both of the methods are explained below with examples.
Include the following namespace in your project:
 
using Alachisoft.NCache.Web.Caching;
 
Using Get Method
 
Here is how you can retrieve items from the cache.
 
Cache _cache = NCache.Caches["mycache"];
// Returns null if item not found
object myObject = _cache.Get("Customer:David:1001");
if (myObject == null)
{
// Item not found
}
 
Using Cache["key"]
 
Here is another way to retrieve items from the cache.
 
Cache _cache = NCache.Caches["mycache"];
// Returns null if item not found
object myObject = _cache["Customer:David:1001"];
if (myObject == null)
{
// Item not found
}
 
Using Contains Method
 
You can also check whether an item exists in the cache or not.
 
 
Cache _cache = NCache.Caches["mycache"];
// Returns true or false
if (_cache.Contains("Customer:David:1001") == false)
{
// Item not found
}
 
 
See Also
 
© Copyright  2014 Alachisoft. All rights reserved.