NCache 4.6 - Online Documentation

Cache Search Returning Keys

 
In case you still require to mirror the behavior of Search API, i.e., return only the keys after a query is executed, you can do so by setting the getData flag to false in ExecuteReader:
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
Execute Reader
 
            Hashtable values = new Hashtable();
            values.Add("ProductName", "Chai");
            values.Add("UnitsInStock", 250);
 
            try
            {
                // Instead of Product, specify fully qualified name of your custom class.
                string query = "SELECT Product where this.ProductName = ?";
 
                ICacheReader reader = cache.ExecuteReader(query, values, false);
 
                // OR 
                string query = "SELECT Product  WHERE this.ProductName = ? and this.UnitsInStock > ?";
 
                ICacheReader reader = cache.ExecuteReader(query, values, false);
 
                if (reader.FieldCount > 0)
                {
                    while (reader.Read())
                    {
                        object category = reader.GetValue(0);
                        //perform operations
                    }
                }
                else
                {
                    // no record exists
                }
                reader.Close();
            }
            catch (OperationFailedException ex)
            {
                // handle exception
            }
 
Search (Deprecated)
 
It is preferable that you use ExecuteReader, as Search will be deprecated in future NCache versions.
 
    Hashtable values = new Hashtable();
            values.Add("ProductName", "Chai");
            values.Add("UnitsInStock", 250);
 
            try
            {
                // Instead of Product, specify fully qualified name of your custom class.
                string query = "SELECT Product where this.ProductName = ?";
 
                ICollection result = cache.Search(query, values);
            }
            catch (OperationFailedException ex)
            {
                // handle exception
            }
 
 
See Also