NCache 4.6 - Online Documentation

Querying NCache Items with respect to Named Tags

 
      To utilize the following APIs, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
  
In the following code example, please specify the fully qualified name of your custom class instead of 'Product' in the query string. If Named Tags are associated with “int” or any other data type then specific syntax to that type will be used.
For example, for values of "int" data type "SELECT System.int32 WHERE this.UnitsAvailable = ?" will be used to query Named Tags.
 
        string query = "SELECT Product WHERE this.Supplier = ?";
 
        Hashtable values = new Hashtable();
        values.Add("UnitsInStock", 4);
        values.Add("Supplier", "Alex");
 
        try
        {
            ICacheReader queryResult = cache.ExecuteReader(query, values, true);
 
            //queryResult contains all keys related to both tags.
 
            if (queryResult.FieldCount > 0)
            {
                while (queryResult.Read())
                {
                    //perform operations
                }
            }
            else
            {
                //no record exists
            }
        }
        catch (OperationFailedException ex)
        {
                //handle exception
        }
 
If you have multiple applications that are sharing same cache and all of them are supposed to add named tags than make sure that same named tags have homogenous data types, e.g., if one client is adding named tag "ProductID" with String data type than all other clients should add values of "ProductID" in String format not in Integer or other for same cache.
 
 
See Also