/// <summary> /// Creates a region. /// </summary> /// <param name="region">The name of the region that is created.</param> /// <returns>If the region has been created successfully or not. Should the region already exist, this method will return false.</returns> public virtual bool CreateRegion(string region) { lock (_mutex) { if (!Regions.ContainsKey(region)) { Regions[region] = new DataRegion <TObject>(); return(true); } } return(false); }
/// <summary> /// Removes an object to a region in the cache. If the region doesn't exist it's created. /// </summary> /// <param name="key">A unique value that is used to store and retrieve the object from the cache. </param> /// <param name="region">The name of the region to remove the object from.</param> public virtual void Remove(string key, string region) { DataRegion <TObject> dataRegion; lock (_mutex) { if (!Regions.TryGetValue(region, out dataRegion)) { dataRegion = new DataRegion <TObject>(); Regions[region] = dataRegion; } } dataRegion.Remove(key); }
/// <summary> /// Adds an object to a region in the cache. If the region doesn't exist it's created. /// </summary> /// <param name="key">A unique value that is used to store and retrieve the object from the cache. </param> /// <param name="value">The object saved to the cache.</param> /// <param name="region">The name of the region to save the object in.</param> public virtual void Add(string key, TObject value, string region) { DataRegion <TObject> dataRegion; lock (_mutex) { if (!Regions.TryGetValue(region, out dataRegion)) { dataRegion = new DataRegion <TObject>(); Regions[region] = dataRegion; } } dataRegion.Add(key, value); }
/// <summary> /// Gets an enumerable list of all cached objects in the specified region. /// </summary> /// <param name="region">The name of the region for which to return a list of all resident objects.</param> /// <returns>An enumerable list of all cached objects in the specified region.</returns> public virtual IEnumerable <KeyValuePair <string, TObject> > GetObjectsInRegion(string region = "default") { DataRegion <TObject> dataRegion; lock (_mutex) { if (!Regions.TryGetValue(region, out dataRegion)) { dataRegion = new DataRegion <TObject>(); Regions[region] = dataRegion; } } return(dataRegion.GetObjects()); }
/// <summary> /// Gets an object from the specified region by using the specified key. /// </summary> /// <param name="key">The unique value that is used to identify the object in the region.</param> /// <param name="region">The name of the region where the object resides.</param> /// <returns>The object that was cached by using the specified key. Null is returned if the key does not exist.</returns> public virtual TObject Get(string key, string region) { DataRegion <TObject> dataRegion; lock (_mutex) { if (!Regions.TryGetValue(region, out dataRegion)) { dataRegion = new DataRegion <TObject>(); Regions[region] = dataRegion; } } return(dataRegion.Get(key)); }