NCache 4.6 - Online Documentation

Cache Search Returning Items

 
Previously, the whole resulting data was returned after query execution using SearchEntries API, which was expensive for the network if the size of the result was too large. That is why, ExecuteReader is used as it processes the query on the server side and then sends the result in chunks (as a dictionary containing keys and values) to the client. As soon as the chunk is exhausted after being enumerated over, the next chunk is sent over to the client.
 
ExecuteReader()returns the result set in tabular form to ICacheReader type of instance. Column count and attribute values can be fetched through their names or through index number fromĀ ICacheReader. Make sure the instance of ICacheReader is always closed after execution, as it is necessary to clean the resources.
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
Execute Reader
 
            string query = "SELECT this.Category, MAX(Prod.Product.ProductID) WHERE this.Category = ? GROUP BY this.Category";
 
            Hashtable values = new Hashtable();
            values.Add("Category", 4);
 
            try
            {
                ICacheReader reader = cache.ExecuteReader(query, values);
 
                //OR to get data
                ICacheReader reader = cache.ExecuteReader(query, values, true);
 
                //OR to get data with a specific chunk size
                ICacheReader reader = cache.ExecuteReader(query, values, true, 50);
 
                if (reader.FieldCount > 0)
                {
                    while (reader.Read())
                    {
                        //you can get value through the field name...
                        object category = reader.GetOrdinal("Category");
 
                        //...or through the index number
                        object result = reader.GetValue(1);
 
                        //perform operations
                    }
                }
                else
                {
                    // no record exists
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                //handle exception
            }
 
SearchEntries (Deprecated)
 
It is preferable that you use ExecuteReader, as SearchEntries will be deprecated in future NCache versions.
 
    string queryString = " SELECT Product where this.ProductID = ?";
            Hashtable values = new Hashtable();
            values.Add("ProductID", 1001);
      
            try
            {
                //Call SearchEntries for fetching result set in key value pairs.
                IDictionary items = cache.SearchEntries(queryString, values);
            }
            catch (OperationFailedException ex)
            {
                // handle exception
            }
 
 
See Also