Ejemplo n.º 1
0
        /// <summary>
        /// This method removes the provided distributed hash from cache if it exists.
        /// </summary>
        /// <typeparam name="T">Generic type argument for distributed hashset.</typeparam>
        /// <param name="distributedHashSet">Instance of the distributed hashset required
        /// to remove from cache.</param>
        private static void RemoveDistributedHashSet <T>(IDistributedHashSet <T> distributedHashSet)
        {
            // If handle for distributed hashset is null, no need to return anything
            if (distributedHashSet == null)
            {
                return;
            }

            // Distributed hashset removed if exists
            _cache.DataTypeManager.Remove(distributedHashSet.Key);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// displays hashset objects
 /// </summary>
 /// <param name="distributedHashSet">hashset to display</param>
 private void DisplayHashSetData(IDistributedHashSet <int> distributedHashSet)
 {
     distributedHashSet.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName);
     Console.WriteLine("Result count: " + distributedHashSet.Count);
     Console.WriteLine("--");
     foreach (int num in distributedHashSet)
     {
         Console.Write(num + "\t");
     }
     Console.WriteLine("\n--");
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This method demonstrates how we can iterate over all the values in a distributed hashset.
        /// </summary>
        /// <typeparam name="T">Generic type argument for distributed hashset.</typeparam>
        /// <param name="distributedHashSet">Instance of the distributed hashset to iterate over.</param>
        private static void IterateOverDistributedHashSet <T>(IDistributedHashSet <T> distributedHashSet)
        {
            // If handle for distributed hashset is null, no need to iterate over anything
            if (distributedHashSet == null)
            {
                return;
            }

            // Print information of distributed hashset whose data is to be printed
            Console.WriteLine("\nIterating over '{0}',", distributedHashSet.Key);
            Console.WriteLine(new string('-', 18 + distributedHashSet.Key.Length));

            // Print each item contained in distributed hashset
            foreach (T item in distributedHashSet)
            {
                Console.WriteLine(" - {0}", item);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// <para>
        /// Fetches (or creates if does not exist) a distributed hashset. The hashset created
        /// through this call is created with an absolute expiration of 1 minute.
        /// </para>
        /// <para>
        /// NOTE : Distributed hashset of primitive data types and string data type ought to be
        /// created only. Created or getting a distributed hashset of any other type does not throw
        /// any exception but upon performing operations, exceptions will be thrown accordingly.
        /// </para>
        /// </summary>
        /// <typeparam name="T">Generic type argument for distributed hashset.</typeparam>
        /// <param name="hashSetName">Name against which the distributed hash
        /// set needed is to be stored.</param>
        /// <returns>Instance of the distributed hashset required.</returns>
        private static IDistributedHashSet <T> GetOrCreate <T>(string hashSetName)
        {
            IDistributedHashSet <T> distributedHashSet = _cache.DataTypeManager.GetHashSet <T>(hashSetName);

            if (distributedHashSet == null)
            {
                // additional properties can be added to the hashset using the DataTypeAttributes class
                // using attributes, properties can be added to the whole hashset
                DataTypeAttributes attributes = new DataTypeAttributes
                {
                    // creating expiration of 1 minute and adding it to attributes
                    Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0))
                };

                // Creating distributed hashSet with absolute expiration
                distributedHashSet = _cache.DataTypeManager.CreateHashSet <T>(hashSetName, attributes);
            }

            return(distributedHashSet);
        }