Exemplo n.º 1
0
        /// <summary>
        /// This method queries items in the cache on which index was defined using NCache Manager.
        /// </summary>
        private static void QueryItemsUsingDefinedIndex()
        {
            //  Query can only be applied to C# Primitive data types:
            //  and for those non primitive data types whose indexes are defined in NCache manager

            string query = "SELECT $Value$ FROM Alachisoft.NCache.Sample.Data.Product WHERE UnitPrice > ?";


            QueryCommand queryCommand = new QueryCommand(query);

            queryCommand.Parameters.Add("UnitPrice", Convert.ToDecimal(100));
            ICacheReader reader = _cache.SearchService.ExecuteReader(queryCommand);

            int counter = 0;

            if (reader.FieldCount > 0)
            {
                while (reader.Read())
                {
                    var product = reader.GetValue <Product>(1);
                    PrintProductDetails(product);
                    counter++;
                }
            }

            Console.WriteLine("{0} cache items fetched from cache using query on unit price.\n", counter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method queries cached data
        /// </summary>
        /// <param name="customer"> Instance of registered continuous query to query cached items</param>
        private static void QueryDataInCache(QueryCommand queryCommand)
        {
            // Getting keyvalue pair via query
            // Much faster way ... avoids round trip to cache
            //ICacheReader cacheReader = _cache.ExecuteReaderCQ(continuousQuery, true);
            ICacheReader cacheReader = _cache.SearchService.ExecuteReader(queryCommand, true);

            if (!cacheReader.IsClosed)
            {
                // Print output on console
                Console.WriteLine("\nFollowing items are fetched with Continuous Query.");

                while (cacheReader.Read())
                {
                    var      asd           = cacheReader.GetValue <object>(0);
                    Customer customerFound = cacheReader.GetValue <Customer>(1);
                    PrintCustomerDetails(customerFound);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method queries items from the cache using projection attributes.
        /// </summary>
        private static void QueryItemsUsingProjection()
        {
            string query = "SELECT Name, Supplier FROM Alachisoft.NCache.Sample.Data.Product WHERE UnitPrice > ?";

            QueryCommand queryCommand = new QueryCommand(query);

            queryCommand.Parameters.Add("UnitPrice", Convert.ToDecimal(100));
            ICacheReader reader = _cache.SearchService.ExecuteReader(queryCommand);

            int counter = 0;

            if (reader.FieldCount > 0)
            {
                while (reader.Read())
                {
                    Console.WriteLine("Name:      " + reader.GetValue <string>("Name"));
                    Console.WriteLine("Supplier:  " + reader.GetValue <string>("Supplier"));
                    Console.WriteLine();
                    counter++;
                }
            }

            Console.WriteLine("{0} cache items fetched from cache using projection query on unit price.\n", counter);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method queries cached keys
        /// </summary>
        /// <param name="customer"> Instance of Query Command to query cached items</param>
        private static void QueryKeysInCache(QueryCommand queryCommand)
        {
            // Getting keys via query
            //ICacheReader cacheReader = _cache.ExecuteReaderCQ(continuousQuery, false);
            ICacheReader cacheReader = _cache.SearchService.ExecuteReader(queryCommand, false);

            if (!cacheReader.IsClosed)
            {
                // Print output on console
                Console.WriteLine("\nFollowing keys are fetched with Continuous Query.");

                while (cacheReader.Read())
                {
                    string key = cacheReader.GetValue <string>(0);

                    Console.WriteLine("Key: " + key);

                    // A second call to cache to fetch the customer
                    //Customer cachedCustomer = (Customer)_cache.Get(key);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method queries Items from NCache using named tags.
        /// </summary>
        private static void QueryItemsUsingNamedTags()
        {
            string       query        = "SELECT $Value$ FROM Alachisoft.NCache.Sample.Data.Product WHERE Supplier = ?";
            QueryCommand queryCommand = new QueryCommand(query);

            // Defining Searching criteria
            queryCommand.Parameters.Add("Supplier", "Tokyo Traders");
            ICacheReader reader = _cache.SearchService.ExecuteReader(queryCommand);

            int counter = 0;

            if (reader.FieldCount > 0)
            {
                while (reader.Read())
                {
                    var product = reader.GetValue <Product>(1);
                    PrintProductDetails(product);
                    counter++;
                }
            }

            Console.WriteLine("{0} cache items fetched from cache using query on named tags.\n", counter);
        }