NCache 4.4 - Online Documentation

Finding Items

 
Items can be retrieved from cache either by using Get method or the cache indexer. Both methods are explained below with examples.
Include the following namespace in your project:
 
using Alachisoft.NCache.Web.Caching;
 
Using Get Method
 
Here is how items can be retrieved fom 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 found
}
 
 
See Also