/// <summary> /// Creates a distributed list to which instances of customers are to be added /// </summary> /// be the key against which distributed list is to be stored.</param> private static void CreateListWithDataTypeAttributes() { //Attribute NamedTags Dictionary NamedTagsDictionary namedTags = new NamedTagsDictionary(); namedTags.Add("Customers", "Loyal"); //Expiration Expiration expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0)); //with Tag Frequent Tag tag = new Tag("Frequent"); //Group for distributed datatype string group = "Potential"; // Item priority Default CacheItemPriority cacheItemPriority = CacheItemPriority.Default; // Resync Operation is disabled ResyncOptions resyncOptions = new ResyncOptions(false); DataTypeAttributes attributes = new DataTypeAttributes { Expiration = expiration, NamedTags = namedTags, Group = group, ResyncOptions = resyncOptions, Priority = cacheItemPriority }; // Creating distributed list with the defined attributes _cache.DataTypeManager.CreateList <Customer>(_datatype, attributes); }
// add a customer info in cache public void AddtCustomerInCache(string key, DataTypeAttributes attributes, FraudRequest customer) { try { // create a list with write behind option // so whenever a cahcnge happen in data it is upadated back to data source WriteThruOptions options = new WriteThruOptions(WriteMode.WriteBehind); IDistributedList <FraudRequest> list = cache.DataTypeManager.CreateList <FraudRequest>(key, attributes); list.WriteThruOptions = options; list.Add(customer); } catch (Exception ex) { throw; } }
/// <summary> /// Creates a distributed list to which instances of customers are to be added /// </summary> private static IList <Customer> GetOrCreateList() { IDistributedList <Customer> distributedList = _cache.DataTypeManager.GetList <Customer>(_listName); if (distributedList == null) { DataTypeAttributes attributes = new DataTypeAttributes { Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0)) }; // Creating distributed list with absolute expiration of 1 minute distributedList = _cache.DataTypeManager.CreateList <Customer>(_listName, attributes); } return(distributedList); }
/// <summary> /// Creates a distributed queue to which customers are to be added /// </summary> private static IDistributedQueue <Customer> GetOrCreateQueue() { IDistributedQueue <Customer> distributedQueue = _cache.DataTypeManager.GetQueue <Customer>(QueueName); if (distributedQueue == null) { DataTypeAttributes attributes = new DataTypeAttributes { Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0)) }; // Creating distributed queue with absolute expiration of 1 minute distributedQueue = _cache.DataTypeManager.CreateQueue <Customer>(QueueName, attributes); } return(distributedQueue); }
/// <summary> /// Creates a distributed counter to which instances of customers are to be added /// </summary> private static ICounter GetOrCreateCounter() { ICounter counter = _cache.DataTypeManager.GetCounter(_counterName); if (counter == null) { DataTypeAttributes attributes = new DataTypeAttributes { Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0)) }; // Creating distributed counter with absolute expiration // to modify cache properties of the counter, provide an instance of DataTypeAttributes in the second parameter counter = _cache.DataTypeManager.CreateCounter(_counterName, attributes); } return(counter); }
/// <summary> /// Creates a distributed Dictionary to which instances of customers are to be added /// </summary> /// <param name="DictionaryName">The name of Dictionary. This name is ultimately going to /// be the key against which distributed Dictionary is to be stored.</param> private static IDictionary <string, Customer> GetOrCreateDictionary(string DictionaryName) { IDistributedDictionary <string, Customer> dictionary = _cache.DataTypeManager.GetDictionary <string, Customer>(_dictionaryName); if (dictionary == null) { //Add expiration details DataTypeAttributes attributes = new DataTypeAttributes { Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0)) }; // Creating distributed Dictionary with absolute expiration of 1 minute dictionary = _cache.DataTypeManager.CreateDictionary <string, Customer>(DictionaryName, attributes); } return(dictionary); }
/// <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); }