Class Cache
Implements the clustered cache for an application
Inheritance
Namespace:
Assembly: Alachisoft.NCache.Web.dll
Syntax
public class Cache : IEnumerable, IDisposable
Remarks
One instance of this class is created per application domain, and it remains valid as long as the application domain remains active. This object is accessible through the Alachisoft.NCache.Web.Caching.NCache.Cache property of the NCache object.
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
DefaultAbsolute
A read only field, used to set expiration for cache entry while adding data to cache. Item will be expired from the cache within DefaultAbsolute value + cache clean up interval. The value for this field is given from NCache Manager. Minimum value for DefaultAbsolute expiration is 5s.
Declaration
public static readonly DateTime DefaultAbsolute
Field Value
Type | Description |
---|---|
System.DateTime |
Examples
The following example demonstrates how to use DefaultAbsolute to add an item to the cache.
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Chai";
string key = "Product:" + product.ProductID;
cache.Add(key, product, null, Cache.DefaultAbsolute, Cache.NoSlidingExpiration, CacheItemPriority.Default);
DefaultAbsoluteLonger
A read only field, used to set expiration for cache entry while adding data to cache. Item will be expired from the cache after DefaultAbsoluteLonger value + cache clean up interval. The value for this field is given from NCache Manager. Minimum value for DefaultAbsoluteLonger expiration is 5s.
Declaration
public static readonly DateTime DefaultAbsoluteLonger
Field Value
Type | Description |
---|---|
System.DateTime |
Examples
The following example demonstrates how to use DefaultAbsoluteLonger to add an item to the cache.
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Coffee";
string key = "Product:" + product.ProductID;
cache.Add(key, product, null, Cache.DefaultAbsoluteLonger, Cache.NoSlidingExpiration, CacheItemPriority.Default);
DefaultSliding
A read only field, used to set expiration for cache entry while adding data to cache. Item will be expired from the cache within DefaultSliding value + cache clean up interval, iff there is no fetching of that particular item. The value for this field is given from NCache Manager. Minimum value for DefaultSliding expiration is 5s.
Declaration
public static readonly TimeSpan DefaultSliding
Field Value
Type | Description |
---|---|
System.TimeSpan |
Examples
The following example demonstrates how to use DefaultSliding to add an item to the cache.
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Tea";
string key = "Product:" + product.ProductID;
cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSliding, CacheItemPriority.Default);
DefaultSlidingLonger
A read only field, used to set expiration for cache entry while adding data to cache. Item will be expired from the cache within DefaultSlidingLonger value + cache clean up interval, iff there is no fetching of that particular item. The value for this field is given from NCache Manager. Minimum value for DefaultSlidingLonger expiration is 5s.
Declaration
public static readonly TimeSpan DefaultSlidingLonger
Field Value
Type | Description |
---|---|
System.TimeSpan |
Examples
The following example demonstrates how to use DefaultSlidingLonger to add an item to the cache.
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Tea";
string key = "Product:" + product.ProductID;
cache.Add(key, product, null, Cache.NoAbsoluteExpiration, Cache.DefaultSlidingLonger, CacheItemPriority.Default);
NoAbsoluteExpiration
Used in the absoluteExpiration
parameter in an Insert method call to
indicate the item should never expire. This field is read-only.
Declaration
public static readonly DateTime NoAbsoluteExpiration
Field Value
Type | Description |
---|---|
System.DateTime |
Remarks
When used, this field sets the absoluteExpiration
parameter equal
to System.DateTime.MaxValue, which is a constant representing the largest possible
System.DateTime value, 12/31/9999 11:59:59 PM.
Examples
The following example demonstrates how to use the NoAbsoluteExpiration field to disable absolute expirations when inserting an item in the Cache.
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(10));
NoLockExpiration
Used as the lockTimeout
parameter in Lock method call
to disable locking expirations. This field is read-only.
Declaration
public static readonly TimeSpan NoLockExpiration
Field Value
Type | Description |
---|---|
System.TimeSpan |
Remarks
When used, this field sets the lockTimeout
parameter equal to the System.TimeSpan.Zero
field, which has a constant value of zero. Then the cache item remains locked untill explicitly released.
Examples
The following example demonstrates how to use the Lock method to add an item to the Cache object using the NoLockExpiration field.
Cache cache = NCache.InitializeCache("myCache");
LockHandle lockHandle = new LockHandle();
cache.Lock("DSN", Cache.NoLockExpiration, out lockHandle);
NoSlidingExpiration
Used as the slidingExpiration
parameter in an Insert method call
to disable sliding expirations. This field is read-only.
Declaration
public static readonly TimeSpan NoSlidingExpiration
Field Value
Type | Description |
---|---|
System.TimeSpan |
Remarks
When used, this field sets the slidingExpiration
parameter equal to the System.TimeSpan.Zero
field, which has a constant value of zero. The cached item then expires
in accordance with the absoluteExpiration
parameter.
Examples
The following example demonstrates how to use the Insert method to add an item to the Cache object using the NoSlidingExpiration field.
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration);
ClientInfo
Displays the information related to this client
Declaration
public virtual ClientInfo ClientInfo { get; }
Property Value
Type | Description |
---|---|
ClientInfo |
Count
Gets the number of items stored in the cache.
Declaration
[TargetMethod(1)]
public virtual long Count { get; }
Property Value
Type | Description |
---|---|
System.Int64 | The number of items stored in the cache. |
Remarks
This property can be useful when monitoring your application's performance or when using ASP.NET tracing functionality.
Note: In a partitioned cluster this operation is an expensive one as it might result in network calls. It is therefore advised to use this property only when required.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
ExceptionsEnabled
Flag that indicates whether exceptions are enabled or not.
Declaration
public virtual bool ExceptionsEnabled { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | true if exceptions are enabled, otherwise false. |
Remarks
If this property is set the Cache object throws exceptions from public operations. If not set no exception is thrown and the operation fails silently. Setting this flag is especially helpful during development phase of application since exceptions provide more information about the specific causes of failure.
Examples
This sample shows how to set the ExceptionsEnabled property.
Cache cache = NCache.InitializeCache("myCache");
cache.ExceptionsEnabled = true;
Item[String]
Gets or sets the cache item at the specified key.
Declaration
public virtual object this[string key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A |
Property Value
Type | Description |
---|---|
System.Object | The specified cache item. |
Remarks
You can use this property to retrieve the value of a specified cache item, or to add an item and a key for it to the cache.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following examples demonstrates using this property to retrieve and insert the values of cached item.
Cache cache = NCache.InitializeCache("myCache");
void cmdReset_Click(object objSender, EventArgs objArgs)
{
txtValue.Text = cache[txtName.Text].ToString();
}
void cmdAdd_Click(object objSender, EventArgs objArgs)
{
if (txtName.Text != "")
{
// Add this item to the cache.
cache[txtName.Text] = txtValue.Text;
}
}
void cmdReset_Click(object objSender, EventArgs objArgs)
{
txtValue.Text = cache[txtName.Text].ToString();
}
void cmdAdd_Click(object objSender, EventArgs objArgs)
{
if (txtName.Text != "")
{
// Add this item to the cache.
cache[txtName.Text] = txtValue.Text;
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Add(String, CacheItem)
Add a CacheItem to the cache
Declaration
[TargetMethod(7)]
public virtual CacheItemVersion Add(string key, CacheItem item)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add an item to the cache with an absolute expiration of 2 minutes from now, a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItem.
object someData = new object();
CacheItem item = new CacheItem(someData);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Add("someData", item);
Add(String, CacheItem, DSWriteOption, DataSourceItemsAddedCallback)
Add a CacheItem to the cache
Declaration
[TargetMethod(8)]
public virtual CacheItemVersion Add(string key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsAddedCallback | onDataSourceItemAdded | A delegate that, if provided, is called when item is added to data source. |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add an item to the cache with an absolute expiration of 2 minutes from now, a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItem.
object someData = new object();
CacheItem item = new CacheItem(someData);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Add("someData", item, DSWriteOption.WriteBehind, new DataSourceItemsAddedCallback(OnDataSourceItemAdded));
Add(String, CacheItem, DSWriteOption, String, DataSourceItemsAddedCallback)
Add a CacheItem to the cache.
Declaration
[TargetMethod(9)]
public virtual CacheItemVersion Add(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | A unique identifier for the data source |
DataSourceItemsAddedCallback | onDataSourceItemAdded | A delegate that, if provided, is called when item is added to data source |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Add(String, Object)
Adds an item into the Cache object with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration.
Declaration
[TargetMethod(1)]
public virtual CacheItemVersion Add(string key, object value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to add an item into an application's cache.
Cache cache = NCache.InitializeCache("myCache");
cache.Add("DSN", connectionString);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Add(String, Object, NamedTagsDictionary)
Adds an item into the Cache object with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration. It also enables associating named tags with the object.
Declaration
[TargetMethod(3)]
public virtual CacheItemVersion Add(string key, object value, NamedTagsDictionary namedTags)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
NamedTagsDictionary | namedTags | A NamedTagsDictionary to associate with the object. |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to add an item into an application's cache.
Cache cache = NCache.InitializeCache("myCache");
NamedTagsDictionary namedTags = new NamedTagsDictionary();
namedTags.Add("Attribute", "value");
cache.Add("DSN", connectionString, namedTags);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Add(String, Object, Tag[])
Declaration
[TargetMethod(2)]
public virtual CacheItemVersion Add(string key, object value, Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
System.Object | value | |
Tag[] | tags |
Returns
Type | Description |
---|---|
CacheItemVersion |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Add(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority)
Declaration
[TargetMethod(5)]
public virtual CacheItemVersion Add(string key, object value, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
System.Object | value | |
CacheDependency | dependency | |
System.DateTime | absoluteExpiration | |
System.TimeSpan | slidingExpiration | |
CacheItemPriority | priority |
Returns
Type | Description |
---|---|
CacheItemVersion |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Add(String, Object, DateTime, TimeSpan, CacheItemPriority)
Declaration
[TargetMethod(6)]
public virtual CacheItemVersion Add(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
System.Object | value | |
System.DateTime | absoluteExpiration | |
System.TimeSpan | slidingExpiration | |
CacheItemPriority | priority |
Returns
Type | Description |
---|---|
CacheItemVersion |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Add(String, Object, String, String)
Adds a value to the cache
Declaration
[TargetMethod(4)]
public virtual CacheItemVersion Add(string key, object value, string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The value that is to be stored |
System.String | group | The data group of the item |
System.String | subGroup | The data group of the item |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Examples
Cache cache = NCache.InitializeCache("myCache");
cache.Add("DSN", value, "CONNECTIONS", null);
AddAsync(String, CacheItem, DSWriteOption, DataSourceItemsAddedCallback)
Add a CacheItem to the cache asynchronously
Declaration
[TargetMethod(2)]
public virtual void AddAsync(string key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsAddedCallback | onDataSourceItemAdded | A delegate that, if provided, is called when item is added to data source. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add an item to the cache with a sliding expiration of 5 minutes, a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItem.
CacheItem item = new CacheItem(timeStamp);
item.SlidingExpiration = new TimeSpan(0,5,0);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.AddAsync("timestamp", item, DSWriteOption.WriteBehind, new DataSourceItemsAddedCallback(OnDataSourceItemAdded));
AddAsync(String, CacheItem, DSWriteOption, String, DataSourceItemsAddedCallback)
Declaration
[TargetMethod(3)]
public virtual void AddAsync(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
CacheItem | item | |
DSWriteOption | dsWriteOption | |
System.String | providerName | |
DataSourceItemsAddedCallback | onDataSourceItemAdded |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
AddAsync(String, Object, AsyncItemAddedCallback, String, String)
Add the object to the cache asynchronously.
Declaration
[TargetMethod(1)]
public virtual void AddAsync(string key, object value, AsyncItemAddedCallback onAsyncItemAddCallback, string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The value that is to be stored |
AsyncItemAddedCallback | onAsyncItemAddCallback | A delegate that, if provided, is called to inform about the status of the operation. |
System.String | group | The data group of the item |
System.String | subGroup | The subGroup of the item |
Examples
The following example demonstrates how to add an object to the cache with group, subGroup and a delegate that notifies the application about the operation status.
First create the AsyncItemAddedCallback.
AsyncItemAddedCallback asyncItemAdded = new AsyncItemAddedCallback(OnAsyncItemAdded);
OnAsyncItemAdded(string key, object result)
{
...
}
Then add the object to the cache.
Cache cache = NCache.InitializeCache("myCache");
cache.AddAsync("timestamp", timestamp, asyncItemAdded, "group-name", "subGroup-name");
AddAsyncOperation(String, Object, CacheDependency, CacheSyncDependency, DateTime, TimeSpan, CacheItemPriority, DSWriteOption, CacheItemRemovedCallback, CacheItemUpdatedCallback, AsyncItemAddedCallback, DataSourceItemsAddedCallback, Boolean, String, String, Tag[], String, String, NamedTagsDictionary, CacheDataNotificationCallback, CacheDataNotificationCallback, EventDataFilter, EventDataFilter, String, Int16, Int16, Int16)
Function that choose the appropriate function of NCache's Cache, that need to be called according to the data provided to it.
Declaration
protected virtual void AddAsyncOperation(string key, object value, CacheDependency dependency, CacheSyncDependency syncDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, DSWriteOption dsWriteOption, CacheItemRemovedCallback onRemoveCallback, CacheItemUpdatedCallback onUpdateCallback, AsyncItemAddedCallback onAsyncItemAddCallback, DataSourceItemsAddedCallback onDataSourceItemAdded, bool isResyncExpiredItems, string group, string subGroup, Tag[] tags, string providerName, string resyncProviderName, NamedTagsDictionary namedTags, CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, string clientId, short updateCallbackId, short removeCallbackId, short dsItemAddedCallbackId)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
System.Object | value | |
CacheDependency | dependency | |
CacheSyncDependency | syncDependency | |
System.DateTime | absoluteExpiration | |
System.TimeSpan | slidingExpiration | |
CacheItemPriority | priority | |
DSWriteOption | dsWriteOption | |
CacheItemRemovedCallback | onRemoveCallback | |
CacheItemUpdatedCallback | onUpdateCallback | |
AsyncItemAddedCallback | onAsyncItemAddCallback | |
DataSourceItemsAddedCallback | onDataSourceItemAdded | |
System.Boolean | isResyncExpiredItems | |
System.String | group | |
System.String | subGroup | |
Tag[] | tags | |
System.String | providerName | |
System.String | resyncProviderName | |
NamedTagsDictionary | namedTags | |
CacheDataNotificationCallback | cacheItemUdpatedCallback | |
CacheDataNotificationCallback | cacheItemRemovedCallaback | |
Alachisoft.NCache.Runtime.Events.EventDataFilter | itemUpdateDataFilter | |
Alachisoft.NCache.Runtime.Events.EventDataFilter | itemRemovedDataFilter | |
System.String | clientId | |
System.Int16 | updateCallbackId | |
System.Int16 | removeCallbackId | |
System.Int16 | dsItemAddedCallbackId |
AddBulk(String[], CacheItem[])
Add array of CacheItem to the cache.
Declaration
[TargetMethod(2)]
public virtual IDictionary AddBulk(string[] keys, CacheItem[] items)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | keys that are added or that alredy exists in the cache and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add items to the cache with an absolute expiration 2 minutes from now, a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItems.
string keys = {"First", "Second"};
CacheItem items = new CacheItem[2]
items[0] = new CacheItem(firstTimeStamp);
items[0].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[0].Priority = CacheItemPriority.High;
items[0].ItemRemoveCallback = onRemove;
items[1] = new CacheItem(secondTimeStamp);
items[1].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[1].Priority = CacheItemPriority.Low;
items[1].ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Add(keys, items);
AddBulk(String[], CacheItem[], DSWriteOption, DataSourceItemsAddedCallback)
Add array of CacheItem to the cache.
Declaration
[TargetMethod(1)]
public virtual IDictionary AddBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemsAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsAddedCallback | onDataSourceItemsAdded | A delegate that, if provided, is called when item is added to data source. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | keys that are added or that alredy exists in the cache and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add items to the cache with an absolute expiration 2 minutes from now, a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItems.
string keys = {"First", "Second"};
CacheItem items = new CacheItem[2]
items[0] = new CacheItem(firstTimeStamp);
items[0].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[0].Priority = CacheItemPriority.High;
items[0].ItemRemoveCallback = onRemove;
items[1] = new CacheItem(secondTimeStamp);
items[1].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[1].Priority = CacheItemPriority.Low;
items[1].ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Add(keys, items, DSWriteOption.WriteBehind, new DataSourceItemsAddedCallback(OnDataSourceItemAdded));
AddBulk(String[], CacheItem[], DSWriteOption, String, DataSourceItemsAddedCallback)
Add array of CacheItem to the cache.
Declaration
[TargetMethod(3)]
public virtual IDictionary AddBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemsAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | A unique identifier for the data source |
DataSourceItemsAddedCallback | onDataSourceItemsAdded | A delegate that, if provided, is called when item is added to data source |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | keys that are added or that alredy exists in the cache and their status. |
AddDependency(String, CacheDependency, Boolean)
Add dependency to the cache item.
Declaration
[TargetMethod(1)]
public virtual bool AddDependency(string key, CacheDependency dependency, bool isResyncRequired)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key used to reference the required object |
CacheDependency | dependency | CacheDependency to be added |
System.Boolean | isResyncRequired | If set, then at the time of expiration, a fresh copy of the item is fetched from the master datasource provided that the read-thru is enabled. Otherwise it is expired as normal. |
Returns
Type | Description |
---|---|
System.Boolean | True if the operation successeded otherwise false |
AddDependency(String, CacheSyncDependency)
Add CacheSyncDependency to the cache item.
Declaration
[TargetMethod(2)]
[Obsolete("This method is deprecated. 'Please use AddDependency(string key, CacheDependency dependency, bool isResyncRequired)'", false)]
public virtual bool AddDependency(string key, CacheSyncDependency syncDependency)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key used to reference the required object |
CacheSyncDependency | syncDependency | CacheSyncDependency to be added |
Returns
Type | Description |
---|---|
System.Boolean | True if the operation successeded otherwise false |
Aggregate(IValueExtractor, IAggregator)
Built upon MapReduce framework, processes distributed data records to return compiled and statistical results for analytical purposes.
Declaration
[TargetMethod(1)]
public virtual object Aggregate(IValueExtractor extractor, IAggregator aggregator)
Parameters
Type | Name | Description |
---|---|---|
IValueExtractor | extractor | Implementation of IValueExtractor to extract the meaningful attributes from given objects |
IAggregator | aggregator | For actual grouping and analytical operations on given data using Map Reduce Combiner and Reducer |
Returns
Type | Description |
---|---|
System.Object | Returns a single result depending upon given extractor. |
Examples
IAggregator can perform following operations Average, Sum, Min, Max, Count, Distinct. If result after aggregation execution is null than default value of built in Aggregator for that specific type is returned. User can also implement custom aggregator, as well as aggregator for custom data types and also for custom functions like Mean, Median, Mode.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
int value = (int)cache.Aggregate(new BasicTypeExtractor(), BuiltInAggregator.IntegerSum());
// IValueExtractor Implementaion
public class BasicTypeExtractor : IValueExtractor
{
public object Extract(object value)
{
try
{
if (value.GetType() == typeof(int))
{
return 0;
}
if (value.GetType() == typeof(float))
{
return 0.0;
}
}
catch (Exception e)
{
//handle exception
}
return value;
}
}
Aggregate(IValueExtractor, IAggregator, IKeyFilter)
Built upon MapReduce framework, processes distributed data records to return compiled and statistical results for analytical purposes.
Declaration
[TargetMethod(3)]
public virtual object Aggregate(IValueExtractor extractor, IAggregator aggregator, IKeyFilter keyFilter)
Parameters
Type | Name | Description |
---|---|---|
IValueExtractor | extractor | Implementation of IValueExtractor to extract the meaningful attributes from given objects |
IAggregator | aggregator | Returns a single result depending upon given extractor. |
IKeyFilter | keyFilter | Instance of IKeyFilter implementation. |
Returns
Type | Description |
---|---|
System.Object | Returns a single result depending upon given extractor. |
Examples
IAggregator can perform following operations Average, Sum, Min, Max, Count, Distinct. If result after aggregation execution is null than default value of built in Aggregator for that specific type is returned. User can also implement custom aggregator, as well as aggregator for custom data types and also for custom functions like Mean, Median, Mode.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
AggregatorKeyFilter keyFilter= new AggregatorKeyFilter();
object result =_cache.Aggregate(new BasicTypeExtractor(), BuiltInAggregator.Count(),keyFilter);
// IValueExtractor Implementaion
public class BasicTypeExtractor : IValueExtractor
{
public object Extract(object value)
{
try
{
if (value.GetType() == typeof(int))
{
return 0;
}
if (value.GetType() == typeof(float))
{
return 0.0;
}
}
catch (Exception e)
{
//handle exception
}
return value;
}
}
//implementation of IKeyFilter
public class AggregatorKeyFilter : IKeyFilter
{
public bool FilterKey(object key)
{
try
{
if (key.ToString().Contains("hungry"))
{
return true;
}
}
catch (Exception exp)
{
//handle exception
}
return false;
}
}
Aggregate(IValueExtractor, IAggregator, IKeyFilter, Int32)
Built upon MapReduce framework, processes distributed data records to return compiled and statistical results for analytical purposes.
Declaration
[TargetMethod(6)]
public virtual object Aggregate(IValueExtractor extractor, IAggregator aggregator, IKeyFilter keyFilter, int timeout)
Parameters
Type | Name | Description |
---|---|---|
IValueExtractor | extractor | Implementation of IValueExtractor to extract the meaningful attributes from given objects |
IAggregator | aggregator | Returns a single result depending upon given extractor. |
IKeyFilter | keyFilter | Instance of IKeyFilter implementation. |
System.Int32 | timeout | Time in millisecond in which if result is not returned, thread will be terminated and exception or null will be given. |
Returns
Type | Description |
---|---|
System.Object | Returns a single result depending upon given extractor |
Examples
IAggregator can perform following operations: Average, Sum, Min, Max, Count, Distinct. If result after aggregation execution is null than default value of built in Aggregator for that specific type is returned. User can also implement custom aggregator, as well as aggregator for custom data types and also for custom functions like Mean, Median, Mode.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
AggregatorKeyFilter keyFilter= new AggregatorKeyFilter();
object result =_cache.Aggregate(new BasicTypeExtractor(), BuiltInAggregator.IntegerMax(),keyFilter,40000);
// IValueExtractor Implementaion
public class BasicTypeExtractor : IValueExtractor
{
public object Extract(object value)
{
try
{
if (value.GetType() == typeof(int))
{
return 0;
}
if (value.GetType() == typeof(float))
{
return 0.0;
}
}
catch (Exception e)
{
//handle exception
}
return value;
}
}
//implementation of IKeyFilter
public class AggregatorKeyFilter : IKeyFilter
{
public bool FilterKey(object key)
{
try
{
if (key.ToString().Contains("hungry"))
{
return true;
}
}
catch (Exception exp)
{
//handle exception
}
return false;
}
}
Aggregate(IValueExtractor, IAggregator, Int32)
Built upon MapReduce framework, processes distributed data records to return compiled and statistical results for analytical purposes.
Declaration
[TargetMethod(2)]
public virtual object Aggregate(IValueExtractor extractor, IAggregator aggregator, int timeout)
Parameters
Type | Name | Description |
---|---|---|
IValueExtractor | extractor | Implementation of IValueExtractor to extract the meaningful attributes from given objects |
IAggregator | aggregator | Returns a single result depending upon given extractor. |
System.Int32 | timeout | Time in millisecond in which if result is not returned, thread will be terminated and exception or null will be given. |
Returns
Type | Description |
---|---|
System.Object | Returns a single result depending upon given extractor. |
Examples
IAggregator can perform following operations Average, Sum, Min, Max, Count, Distinct. If result after aggregation execution is null than default value of built in Aggregator for that specific type is returned. User can also implement custom aggregator, as well as aggregator for custom data types and also for custom functions like Mean, Median, Mode.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
object result =_cache.Aggregate(new BasicTypeExtractor(), BuiltInAggregator.Count(), 60000);
// IValueExtractor Implementaion
public class BasicTypeExtractor : IValueExtractor
{
public object Extract(object value)
{
try
{
if (value.GetType() == typeof(int))
{
return 0;
}
if (value.GetType() == typeof(float))
{
return 0.0;
}
}
catch (Exception e)
{
//handle exception
}
return value;
}
}
Aggregate(IValueExtractor, IAggregator, String, Hashtable)
Declaration
[TargetMethod(4)]
public virtual object Aggregate(IValueExtractor extractor, IAggregator aggregator, string query, Hashtable parameters)
Parameters
Type | Name | Description |
---|---|---|
IValueExtractor | extractor | |
IAggregator | aggregator | |
System.String | query | |
System.Collections.Hashtable | parameters |
Returns
Type | Description |
---|---|
System.Object |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Aggregate(IValueExtractor, IAggregator, String, Hashtable, Int32)
Built upon MapReduce framework, processes distributed data records to return compiled and statistical results for analytical purposes.
Declaration
[TargetMethod(5)]
public virtual object Aggregate(IValueExtractor extractor, IAggregator aggregator, string query, Hashtable parameters, int timeout)
Parameters
Type | Name | Description |
---|---|---|
IValueExtractor | extractor | Implementation of IValueExtractor to extract the meaningful attributes from given objects |
IAggregator | aggregator | Returns a single result depending upon given extractor. |
System.String | query | Simple sql like NCache query string |
System.Collections.Hashtable | parameters | NCache query string searchable parameters. |
System.Int32 | timeout | Time in millisecond in which if result is not returned, thread will be terminated and exception or null will be returned. |
Returns
Type | Description |
---|---|
System.Object | Returns a single result depending upon given extractor. |
Examples
IAggregator can perform following operations Average, Sum, Min, Max, Count, Distinct. If result after aggregation execution is null than default value of built in Aggregator for that specific type is returned. User can also implement custom aggregator, as well as aggregator for custom data types and also for custom functions like Mean, Median, Mode.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Clothes", "", 4, 2);
product2 = new Product(4, "Shoes", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
Hashtable values = new Hashtable();
values.Add("Category", "Clothes");
String query = "SELECT Product WHERE this.Category=?;
object result =_cache.Aggregate(new BasicTypeExtractor(), BuiltInAggregator.Count(),query,values, 50000);
// IValueExtractor Implementaion
public class BasicTypeExtractor : IValueExtractor
{
public object Extract(object value)
{
try
{
if (value.GetType() == typeof(int))
{
return 0;
}
if (value.GetType() == typeof(float))
{
return 0.0;
}
}
catch (Exception e)
{
//handle exception
}
return value;
}
}
Clear()
Removes all elements from the Cache.
Declaration
[TargetMethod(1)]
public virtual void Clear()
Remarks
In most of the cases this method's implementation is close to O(1).
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to check for containment of an item in the Cache.
Cache cache = NCache.InitializeCache("myCache");
cache.Clear();
Clear(DSWriteOption, DataSourceClearedCallback)
Removes all elements from the Cache.
Declaration
[TargetMethod(2)]
[Obsolete("This method is deprecated. 'Please use Clear()'", false)]
public virtual void Clear(DSWriteOption updateOpt, DataSourceClearedCallback dataSourceClearedCallback)
Parameters
Type | Name | Description |
---|---|---|
DSWriteOption | updateOpt | Options regarding updating data source |
DataSourceClearedCallback | dataSourceClearedCallback | A delegate that, if provided, is called when data source is cleared. |
Remarks
In most of the cases this method's implementation is close to O(1).
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to clear the Cache.
OnDataSourceCleared(object result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Clear(DSWriteOption.WriteBehind, new DataSourceClearedCallback(OnDataSourceCleared));
ClearAsync(AsyncCacheClearedCallback)
Removes all elements from the Cache asynchronously.
Declaration
[TargetMethod(1)]
public virtual void ClearAsync(AsyncCacheClearedCallback onAsyncCacheClearCallback)
Parameters
Type | Name | Description |
---|---|---|
AsyncCacheClearedCallback | onAsyncCacheClearCallback |
Remarks
This is similar to Clear() except that the operation is performed asynchronously. A CacheCleared event is fired upon successful completion of this method.It is not possible to determine if the actual operation has failed, therefore use this operation for the cases when it does not matter much.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
A delegate that, if provided, is called when data source is cleared. A delegate that, that can be used to get the result of the Asynchronous Clear operation. Options regarding updating data sourceExamples
The following example demonstrates how to clear the Cache.
void OnAsyncCacheCleared(object result)
{
...
}
Cache _cache = NCache.InitializeCache("myCache");
_cache.ClearAsync(new AsyncCacheClearedCallback(OnAsyncCacheCleared));
ClearAsync(DSWriteOption, AsyncCacheClearedCallback, DataSourceClearedCallback)
Declaration
[TargetMethod(2)]
[Obsolete("This method is deprecated. 'Please use Clear()'", false)]
public virtual void ClearAsync(DSWriteOption updateOpt, AsyncCacheClearedCallback onAsyncCacheClearCallback, DataSourceClearedCallback dataSourceClearedCallback)
Parameters
Type | Name | Description |
---|---|---|
DSWriteOption | updateOpt | |
AsyncCacheClearedCallback | onAsyncCacheClearCallback | |
DataSourceClearedCallback | dataSourceClearedCallback |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
ClearClientCache()
Removes all elements from the client cache.
Declaration
[TargetMethod(1)]
public virtual void ClearClientCache()
Examples
The following example demonstrates how to clear the client cache.
Cache cache = NCache.InitializeCache("myCache");
cache.ClearClientCache();
ClearClientCacheAsync(AsyncCacheClearedCallback)
Declaration
[TargetMethod(1)]
public virtual void ClearClientCacheAsync(AsyncCacheClearedCallback onAsyncCacheClearCallback)
Parameters
Type | Name | Description |
---|---|---|
AsyncCacheClearedCallback | onAsyncCacheClearCallback |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Contains(String)
Determines whether the cache contains a specific key.
Declaration
[TargetMethod(1)]
public virtual bool Contains(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to locate in the Cache. |
Returns
Type | Description |
---|---|
System.Boolean | true if the Cache contains an element with the specified key; otherwise, false. |
Remarks
In most of the cases this method's implementation is close to O(1).
Note: In a partitioned cluster this operation is an expensive one as it might result in network calls. It is therefore advised to use this property only when required.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to check for containment of an item in the Cache.
Cache cache = NCache.InitializeCache("myCache");
if(cache.Contains("MyTextBox.Value"))
{
Response.Write("Item found!");
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Delete(String)
Removes the object from the Cache.
Declaration
[TargetMethod(1)]
public virtual void Delete(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Delete("timestamp");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Delete(String, CacheItemVersion)
Removes an item from cache if the specified version is still the most recent version in the cache.
Declaration
[TargetMethod(5)]
public virtual void Delete(string key, CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of item to be removed |
CacheItemVersion | version | The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache. |
Examples
The following example demonstrates how to remove a locked item from the cache.
First create a CacheItem.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item in the cache.
theCache.Add("cachedItemKey", new "cachedItemValue");
Create the CacheItemVersion.
CacheItemVersion version = new CacheItemVersion();
Get the added item from cache and get the item version.
object cachedItem = theCache.Get("cachedItemKey", DSReadOption.None, ref version);
if (cachedItem != null)
{
try
{
//Now remove the cached item using version acquired earlier.
object removedItem = theCache.Remove("cachedItemKey", version);
}
catch (OperationFailedException ex)
{
//Do something
}
}
Delete(String, DSWriteOption, DataSourceItemsRemovedCallback)
Removes the object from the Cache.
Declaration
[TargetMethod(2)]
public virtual void Delete(string key, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating the data source. |
DataSourceItemsRemovedCallback | onDataSourceItemRemovedCallback | A delegate that, if provided, is called when item is removed from data source. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Remove("timestamp", DSWriteOption.None, null, "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Delete(String, DSWriteOption, String, DataSourceItemsRemovedCallback)
Declaration
[TargetMethod(3)]
public virtual void Delete(string key, DSWriteOption dsWriteOption, string providerName, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
DSWriteOption | dsWriteOption | |
System.String | providerName | |
DataSourceItemsRemovedCallback | onDataSourceItemRemovedCallback |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Delete(String, LockHandle)
Removes an item from cache if it is not already locked or if the correct lock-id is specified.
Declaration
[TargetMethod(4)]
public virtual void Delete(string key, LockHandle lockHandle)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of item to be removed |
LockHandle | lockHandle | If the item is locked then, it can be removed only if the correct lockHandle is specified. |
Examples
The following example demonstrates how to remove a locked item from the cache.
First create a CacheItem.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item int the cache.
theCache.Add("cachedItemKey", "cachedItemValue");
Create the lock-handle.
LockHandle lockHandle = new LockHandle();
Get the added item from cache and acquire a lock.
object cachedItem = theCache.Get("cachedItemKey", ref lockHandle, true);
if (cachedItem != null)
{
try
{
//Now remove the cached item using lockHandle acquired earlier.
object removedItem = theCache.Remove("cachedItemKey", lockHandle);
}
catch (OperationFailedException ex)
{
//Do something
}
}
DeleteBulk(String[])
Removes the objects from the Cache.
Declaration
[TargetMethod(2)]
public virtual void DeleteBulk(string[] keys)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the item. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
cache.Remove(keys);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
DeleteBulk(String[], DSWriteOption, DataSourceItemsRemovedCallback)
Removes the objects from the Cache.
Declaration
[TargetMethod(1)]
public virtual void DeleteBulk(string[] keys, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemsRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsRemovedCallback | onDataSourceItemsRemovedCallback | A delegate that, if provided, is called when item is removed from data source. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
cache.Remove(keys, DSWriteOption.WriteBehind, new DataSourceItemsRemovedCallback(OnDataSourceItemsRemoved), "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
DeleteBulk(String[], DSWriteOption, String, DataSourceItemsRemovedCallback)
Removes the objects from the Cache.
Declaration
[TargetMethod(3)]
public virtual void DeleteBulk(string[] keys, DSWriteOption dsWriteOption, string providerName, DataSourceItemsRemovedCallback onDataSourceItemsRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | |
DataSourceItemsRemovedCallback | onDataSourceItemsRemovedCallback | A delegate that, if provided, is called when A unique identifier for the data source item is removed from data source. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
cache.Remove(keys, DSWriteOption.WriteBehind, new DataSourceItemsRemovedCallback(OnDataSourceItemsRemoved), "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Dispose()
Decerements the reference count of the cache and performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public virtual void Dispose()
Remarks
The behavior of this method depends upon the cache's sharing mode (inproc/outproc) specified in the configuration.
If the application uses the cache in inproc mode, calling Dispose closes the cache and releases the resources used by it. If in a cluster the calling node leaves the cluster as well.
If the application uses the cache in outproc mode, calling Dispose releases the reference to the cache object. The cache itself remains operational and cluster remains intact.
ExecuteNonQuery(String, IDictionary)
Executes delete statements on Cache.
Declaration
[TargetMethod(1)]
public virtual int ExecuteNonQuery(string query, IDictionary values)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax |
System.Collections.IDictionary | values | The IDictionary of atribute names and values. |
Returns
Type | Description |
---|---|
System.Int32 | returns the number of rows affected. |
Examples
Only Delete Query is supported yet.
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache = NCache.InitializeCache("myCache");
Hashtable values = new Hashtable();
values.Add("Name", "Paul Jones");
string query="delete Test.Application.Employee where this.Name = ?";
ICacheReader reader=_cache.ExecuteNonQuery(query,values);
values.Clear();
values.Add("Salary", 2000);
query="delete Test.Application.Employee where this.Salary > ?";
reader=_cache.ExecuteNonQuery(query,values);
values.Clear();
values.Add("Name", "Paul jones");
values.Add("Salary", 2000);
query="delete Test.Application.Employee where this.Name = ? and this.Salary > ?";
reader=_cache.ExecuteNonQuery(query,values);
values.Clear();
values.Add("Name", "Paul Jones");
values.Add("Salary", 2000);
query="delete Test.Application.Employee where Not(this.Name = 'Paul Jones' and this.Salary > 2000)";
reader=_cache.ExecuteNonQuery(query,values);
ExecuteReader(String, IDictionary)
Performs search on the Cache based on the query specified.
Declaration
[TargetMethod(2)]
public virtual ICacheReader ExecuteReader(string query, IDictionary values)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of atribute names and values. |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache = NCache.InitializeCache("myCache");
Hashtable values = new Hashtable();
values.Add("Name", "Paul Jones");
string query="select Test.Application.Employee where this.Name = ?";
ICacheReader reader=_cache.ExecuteReader(query,values);
values.Clear();
values.Add("Salary", 2000);
query="select Test.Application.Employee where this.Salary > ?";
result=_cache.ExecuteReader(query,values);
values.Clear();
values.Add("Name", "Paul jones");
values.Add("Salary", 2000);
query="select Test.Application.Employee where this.Name = ? and this.Salary > ?";
result=_cache.ExecuteReader(query,values);
values.Clear();
values.Add("Name", "Paul Jones");
values.Add("Salary", 2000);
query="select Test.Application.Employee where Not(this.Name = 'Paul Jones' and this.Salary > 2000)";
reader=_cache.ExecuteReader(query,values);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
ExecuteReader(String, IDictionary, Boolean)
Performs search on the Cache based on the query specified.
Declaration
[TargetMethod(3)]
public virtual ICacheReader ExecuteReader(string query, IDictionary values, bool getData)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of atribute names and values. |
System.Boolean | getData | Flag to recieve the values/data alongwith keys |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
string query="SELECT Product WHERE this.ProductName = ? and this.UnitsInStock > ?";
Hashtable values = new Hashtable();
values.Add("ProductName", "Chai");
values.Add("UnitsInStock", 250);
try
{
ICacheReader reader = cache.ExecuteReader(query, values, true);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
}
catch
{
//handle exception
}
ExecuteReader(String, IDictionary, Boolean, Int32)
Performs search on the Cache based on the query specified.
Declaration
[TargetMethod(1)]
public virtual ICacheReader ExecuteReader(string query, IDictionary values, bool getData, int chunkSize)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of atribute names and values. |
System.Boolean | getData | Flag to recieve the values/data alongwith keys |
System.Int32 | chunkSize | Size of data/keys packets recieved after search, default value is 512 * 1024 kb's |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache= NCache.InitializeCache("myCache");
Hashtable values = new Hashtable();
values.Add("ProductName", "Chai");
values.Add("UnitsInStock", 250);
// Instead of Product, specify fully qualified name of your custom class.
string query = "SELECT Product where this.ProductName = ?";
try
{
ICacheReader reader = cache.ExecuteReader(query, values, true, 50);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
}
catch
{
//handle exception
}
ExecuteReaderCQ(ContinuousQuery)
Opens ExecuteReader(String, IDictionary, Boolean, Int32) on server nodes to execute query, also registers continous query call backs for data, that falls on query's criteria; if any changes occur in that data.
Declaration
[TargetMethod(1)]
public virtual ICacheReader ExecuteReaderCQ(ContinuousQuery cquery)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | cquery | simple SQL like query syntax to query objects from cache |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache reader of first chunk of data on execution of data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache = NCache.InitializeCache("mycache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2); product2 = new Product(4, "Tunnbr?d", "", 5, 9); string qry = "SELECT Product WHERE this.ProductQuantity = ?;" Hashtable indexTable = new Hashtable(); indexTable.Add("ProductQuantity", 9); ContinuousQuery cQuery = new ContinuousQuery(qry, indexTable);
_cache.Add("2202", product1); _cache.Add("2203", product2); cQuery.RegisterNotification(new QueryDataNotificationCallback(QueryItemCallBack), EventType.ItemUpdated | EventType.ItemRemoved, EventDataFilter.None);
ICacheReader reader = _cache.ExecuteReaderCQ(cQuery); if (reader.FieldCount > 0) { while (reader.Read()) { object category = reader.GetValue(0); //perform operations } } else { //perform operations } reader.Close();
public void QueryItemCallBack(string key, CQEventArg arg) { switch (arg.EventType) { case EventType.ItemRemoved: //do something break; case EventType.ItemUpdated: //do something break; case EventType.ItemAdded: //do something break; } }
ExecuteReaderCQ(ContinuousQuery, Boolean)
Opens ExecuteReader(String, IDictionary, Boolean, Int32) on server nodes to execute query, also registers continous query call backs for data, that falls on query's criteria; if any changes occur in that data.
Declaration
[TargetMethod(2)]
public virtual ICacheReader ExecuteReaderCQ(ContinuousQuery cquery, bool getData)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | cquery | simple SQL like query syntax to query objects from cache |
System.Boolean | getData | Flag to recieve the values/data alongwith keys |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache reader of first chunk of data on execution of data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache = NCache.InitializeCache("mycache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2); product2 = new Product(4, "Tunnbr?d", "", 5, 9); string qry = "SELECT Product WHERE this.ProductID = ?;" Hashtable indexTable = new Hashtable(); indexTable.Add("ProductID", 4); ContinuousQuery cQuery = new ContinuousQuery(qry, indexTable);
_cache.Add("2202", product1); _cache.Add("2203", product2); cQuery.RegisterNotification(new QueryDataNotificationCallback(QueryItemCallBack), EventType.ItemUpdated | EventType.ItemRemoved, EventDataFilter.None);
ICacheReader reader = _cache.ExecuteReaderCQ(cQuery,true);
if (reader.FieldCount > 0) { while (reader.Read()) { object category = reader.GetValue(0); //perform operations } } else { //perform operations } reader.Close();
public void QueryItemCallBack(string key, CQEventArg arg) { switch (arg.EventType) { case EventType.ItemRemoved: //do something break; case EventType.ItemUpdated: //do something break; case EventType.ItemAdded: //do something break; } }
ExecuteReaderCQ(ContinuousQuery, Boolean, Int32)
Opens ExecuteReader(String, IDictionary, Boolean, Int32) on server nodes to execute query, also registers
Declaration
[TargetMethod(3)]
public virtual ICacheReader ExecuteReaderCQ(ContinuousQuery query, bool getData, int chunkSize)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | query | simple SQL like query syntax to query objects from cache |
System.Boolean | getData | Flag to recieve the values/data alongwith keys |
System.Int32 | chunkSize | Size of data/keys packets recieved after search, default value is 512 * 1024 kb's |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache reader of first chunk of data on execution of data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache = NCache.InitializeCache("mycache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2); product2 = new Product(4, "Tunnbr?d", "", 5, 9); string qry = "SELECT Product where this.ProductName = ?"; Hashtable indexTable = new Hashtable(); indexTable.Add("ProductName", "Tunnbr?d"); ContinuousQuery cQuery = new ContinuousQuery(qry, indexTable);
_cache.Add("2202", product1); _cache.Add("2203", product2);
cQuery.RegisterNotification(new QueryDataNotificationCallback(QueryItemCallBack), EventType.ItemUpdated | EventType.ItemRemoved, EventDataFilter.None);
ICacheReader reader = _cache.ExecuteReaderCQ(cQuery,true,50); if (reader.FieldCount > 0) { while (reader.Read()) { object category = reader.GetValue(0); //perform operations } } else { //perform operations } reader.Close();
public void QueryItemCallBack(string key, CQEventArg arg) { switch (arg.EventType) { case EventType.ItemRemoved: //do something break; case EventType.ItemUpdated: //do something break; case EventType.ItemAdded: //do something break; } }
ExecuteTask(MapReduceTask)
Executes the MapReduce task on the cache.
Declaration
[TargetMethod(1)]
public virtual ITrackableTask ExecuteTask(MapReduceTask task)
Parameters
Type | Name | Description |
---|---|---|
MapReduceTask | task | Instance of a MapReduceTask. |
Returns
Type | Description |
---|---|
ITrackableTask | Returns an instance to track the submitted task for result and status |
Examples
Note: Implemeting IReducerFactory,ICombinerFactory and ICmobiner is optional.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
MapReduceTask mapReduceTask = new MapReduceTask();
mapReduceTask.Mapper = new WordCountMapper();
mapReduceTask.Combiner = new WordCountCombinerFactory();
mapReduceTask.Reducer = new WordCountReducerFactory();
ITrackableTask trackableInstance = _cache.ExecuteTask(mapReduceTask);
//Mapper implementation
public class WordCountMapper : IMapper
{
string[] parsedline;
string line;
public void Map(Object key, Object value, IOutputMap context)
{
line = value.ToString();
parsedline = line.Split(' ');
for (int i = parsedline.Length; i>=0; i++)
{
context.Emit(parsedline[i], 1);
}
}
public void Dispose()
{
// Release Resources
}
}
//CombinerFactory Implementation
public class WordCountCombinerFactory : ICombinerFactory
{
public ICombiner Create(object key)
{
WordCountCombiner wcCombiner = new WordCountCombiner();
return wcCombiner;
}
}
//ICombiner Implementation
public class WordCountCombiner : ICombiner
{
int count = 0;
public void BeginCombine()
{
//any initialization
}
public void Combine(object value)
{
count += int.Parse(value.ToString());
}
public object FinishChunk()
{
return count;
}
public void Dispose()
{
// Release Resources
}
}
//IReducerFactory Implementation
public class WordCountReducerFactory : IReducerFactory
{
public IReducer Create(object key)
{
WordCountReducer wcReducer = new WordCountReducer(key);
return wcReducer;
}
}
//IReducer Implementation
public class WordCountReducer : IReducer
{
int count = 0;
object key;
public WordCountReducer(object value)
{
key = value;
}
public void BeginReduce()
{
//perform operations
}
public void Reduce(object value)
{
count += int.Parse(value.ToString());
}
public KeyValuePair FinishReduce()
{
KeyValuePair kvp = null;
kvp.Key = key;
kvp.Value = count;
return kvp;
}
public void Dispose()
{
// Release Resources
}
}
ExecuteTask(MapReduceTask, IKeyFilter)
Executes the MapReduce task on the cache using specified KeyFilter implementation.
Declaration
[TargetMethod(2)]
public virtual ITrackableTask ExecuteTask(MapReduceTask task, IKeyFilter keyFilter)
Parameters
Type | Name | Description |
---|---|---|
MapReduceTask | task | Instance of a MapReduceTask. |
IKeyFilter | keyFilter | Instance of IKeyFilter implementation. |
Returns
Type | Description |
---|---|
ITrackableTask | Returns an instance to track the submitted task for result and status. |
Examples
Note: Implemeting IReducerFactory,ICombinerFactory and ICmobiner is optional.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
MapReduceKeyFilter keyFilter= new MapReduceKeyFilter();
MapReduceTask mapReduceTask = new MapReduceTask();
mapReduceTask.Mapper = new WordCountMapper();
mapReduceTask.Combiner = new WordCountCombinerFactory();
mapReduceTask.Reducer = new WordCountReducerFactory();
ITrackableTask trackableInstance = _cache.ExecuteTask(mapReduceTask,keyFilter);
//implementation of IKeyFilter
public class MapReduceKeyFilter : IKeyFilter
{
public bool FilterKey(object key)
{
try
{
if (key.ToString().Contains("hungry"))
{
return true;
}
}
catch (Exception exp)
{
//handle exception
}
return false;
}
}
//Mapper implementation
public class WordCountMapper : IMapper
{
string[] parsedline;
string line;
public void Map(Object key, Object value, IOutputMap context)
{
line = value.ToString();
parsedline = line.Split(' ');
for (int i = parsedline.Length; i>=0; i++)
{
context.Emit(parsedline[i], 1);
}
}
public void Dispose()
{
// Release Resources
}
}
//CombinerFactory Implementation
public class WordCountCombinerFactory : ICombinerFactory
{
public ICombiner Create(object key)
{
WordCountCombiner wcCombiner = new WordCountCombiner();
return wcCombiner;
}
}
//ICombiner Implementation
public class WordCountCombiner : ICombiner
{
int count = 0;
public void BeginCombine()
{
//any initialization
}
public void Combine(object value)
{
count += int.Parse(value.ToString());
}
public object FinishChunk()
{
return count;
}
public void Dispose()
{
// Release Resources
}
}
//IReducerFactory Implementation
public class WordCountReducerFactory : IReducerFactory
{
public IReducer Create(object key)
{
WordCountReducer wcReducer = new WordCountReducer(key);
return wcReducer;
}
}
//IReducer Implementation
public class WordCountReducer : IReducer
{
int count = 0;
object key;
public WordCountReducer(object value)
{
key = value;
}
public void BeginReduce()
{
//perform operations
}
public void Reduce(object value)
{
count += int.Parse(value.ToString());
}
public KeyValuePair FinishReduce()
{
KeyValuePair kvp = null;
kvp.Key = key;
kvp.Value = count;
return kvp;
}
public void Dispose()
{
// Release Resources
}
}
ExecuteTask(MapReduceTask, String, Hashtable)
Executes the MapReduce task on the resultant items with specified query.
Declaration
[TargetMethod(3)]
public virtual ITrackableTask ExecuteTask(MapReduceTask task, string query, Hashtable parameters)
Parameters
Type | Name | Description |
---|---|---|
MapReduceTask | task | Instance of a MapReduceTask. |
System.String | query | Simple sql like NCache query string |
System.Collections.Hashtable | parameters | NCache query string searchable parameters. |
Returns
Type | Description |
---|---|
ITrackableTask | Returns an instance to track the submitted task for result and status. |
Examples
Note: Implemeting IReducerFactory,ICombinerFactory and ICmobiner is optional.
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Clothes", "", 4, 2);
product2 = new Product(4, ""Shoes", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
MapReduceTask mapReduceTask = new MapReduceTask();
mapReduceTask.Mapper = new WordCountMapper();
mapReduceTask.Combiner = new WordCountCombinerFactory();
mapReduceTask.Reducer = new WordCountReducerFactory();
Hashtable values = new Hashtable();
values.Add("Category", "Clothes");
string query = "SELECT Product WHERE this.Category IN (?)";
ITrackableTask trackableInstance = _cache.ExecuteTask(mapReduceTask,query,values);
//Mapper implementation
public class WordCountMapper : IMapper
{
string[] parsedline;
string line;
public void Map(Object key, Object value, IOutputMap context)
{
line = value.ToString();
parsedline = line.Split(' ');
for (int i = parsedline.Length; i>=0; i++)
{
context.Emit(parsedline[i], 1);
}
}
public void Dispose()
{
// Release Resources
}
}
//CombinerFactory Implementation
public class WordCountCombinerFactory : ICombinerFactory
{
public ICombiner Create(object key)
{
WordCountCombiner wcCombiner = new WordCountCombiner();
return wcCombiner;
}
}
//ICombiner Implementation
public class WordCountCombiner : ICombiner
{
int count = 0;
public void BeginCombine()
{
//any initialization
}
public void Combine(object value)
{
count += int.Parse(value.ToString());
}
public object FinishChunk()
{
return count;
}
public void Dispose()
{
// Release Resources
}
}
//IReducerFactory Implementation
public class WordCountReducerFactory : IReducerFactory
{
public IReducer Create(object key)
{
WordCountReducer wcReducer = new WordCountReducer(key);
return wcReducer;
}
}
//IReducer Implementation
public class WordCountReducer : IReducer
{
int count = 0;
object key;
public WordCountReducer(object value)
{
key = value;
}
public void BeginReduce()
{
//perform operations
}
public void Reduce(object value)
{
count += int.Parse(value.ToString());
}
public KeyValuePair FinishReduce()
{
KeyValuePair kvp = null;
kvp.Key = key;
kvp.Value = count;
return kvp;
}
public void Dispose()
{
// Release Resources
}
}
Finalize()
Finalizer for this object.
Declaration
protected void Finalize()
Get(String)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(7)]
public virtual object Get(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
cache.Get("MyTextBox.Value");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Get(String, ref CacheItemVersion)
Retrieves the specified item from the Cache object. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(4)]
public virtual object Get(string key, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", ref version);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Get(String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(8)]
public virtual object Get(string key, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
string textBoxValue = (string) cache.Get("MyTextBox.Value", DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Get(String, DSReadOption, ref CacheItemVersion)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it in the cache. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(3)]
public virtual object Get(string key, DSReadOption dsReadOption, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
DSReadOption | dsReadOption | Options regarding reading from data source. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", DSReadOption.ReadThru, ref version);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Get(String, String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(1)]
public virtual object Get(string key, string providerName, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | providerName | A specific name for the data source |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Get(String, String, DSReadOption, ref CacheItemVersion)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it in the cache. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(5)]
public virtual object Get(string key, string providerName, DSReadOption dsReadOption, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | providerName | A specific name for the data source |
DSReadOption | dsReadOption | Options regarding reading from data source. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Get(String, String, String, DSReadOption)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it against the given group and sub group.
Declaration
[TargetMethod(6)]
public virtual object Get(string key, string group, string subGroup, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | group | The name of the group which the item belongs to. |
System.String | subGroup | The name of the subGroup within a group. |
DSReadOption | dsReadOption | Options regarding reading from data source. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", "Customer", null, DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
Get(String, TimeSpan, ref LockHandle, Boolean)
Retrieves the specified item from the Cache object if it is not already locked. Otherwise returns null (Nothing in Visual Basic). This is different from the normal Get operation where an item is returned ignoring the lock altogether.
Declaration
[TargetMethod(2)]
public virtual object Get(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.TimeSpan | lockTimeout | The TimeSpan after which the lock is automatically released. |
LockHandle | lockHandle | An instance of LockHandle to hold the lock information. |
System.Boolean | acquireLock | A flag to determine whether to acquire a lock or not. |
Returns
Type | Description |
---|---|
System.Object | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the cached value and acquire a lock at the same time.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
theCache.Add("cachedItemKey", new CacheItem("cachedItemValue"));
LockHandle lockHandle = new LockHandle();
object cachedItem = theCache.Get("cachedItemKey", Cache.NoLockingExpiration, ref lockHandle, true);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
GetBulk(String[])
Retrieves the object from the cache for the given keys as key value pairs
Declaration
[TargetMethod(2)]
public virtual IDictionary GetBulk(string[] keys)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The keys against which items are to be fetched. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The retrieved cache items. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
IDictionary items = cache.Get(keys);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
GetBulk(String[], DSReadOption)
Retrieves the object from the cache for the given keys as key value pairs
Declaration
[TargetMethod(1)]
public virtual IDictionary GetBulk(string[] keys, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The keys against which items are to be fetched. |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The retrieved cache items. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
IDictionary items = cache.Get(keys, DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
GetBulk(String[], String, DSReadOption)
Retrieves the object from the cache for the given keys as key value pairs
Declaration
[TargetMethod(3)]
public virtual IDictionary GetBulk(string[] keys, string providerName, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The keys against which items are to be fetched. |
System.String | providerName | The datasource provider name for read-through operation |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The retrieved cache items. |
GetByAllTags(Tag[])
Returns the cached objects that have all the same tags in common. (Returns the Intersection set.)
Declaration
[TargetMethod(1)]
public virtual Hashtable GetByAllTags(Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
Tag[] | tags | An array of Tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.Hashtable | A dictionary containing cache keys and associated objects. |
Examples
The following example demonstrates how to get the objects that have all the specified tags in common.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");
Hashtable table = cache.GetByAllTags(tags);
GetByAnyTag(Tag[])
Returns the cached objects that have any of the same tags in common. (Returns the Union set.)
Declaration
[TargetMethod(1)]
public virtual Hashtable GetByAnyTag(Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
Tag[] | tags | An array of Tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.Hashtable | A dictionary containing cache keys and associated objects. |
Examples
The following example demonstrates how to get the objects that have any of the specified tags in common.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");
Hashtable table = cache.GetByAnyTag(tags);
GetByTag(Tag)
Gets all the cached objects with the specified tag.
Declaration
[TargetMethod(1)]
public virtual Hashtable GetByTag(Tag tag)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | The tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.Hashtable | Returns a dictionary containing the cache keys and associated objects. |
Examples
The following example demonstrates how to get the objects with the specified tag.
Cache cache = NCache.InitializeCache("myCache");
Tag tag = new Tag("Sports");
Hashtable table = cache.GetByTag(tag);
GetCacheItem(String)
Get the cache item stored in cache.
Declaration
[TargetMethod(1)]
public virtual CacheItem GetCacheItem(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key used to reference the desired object |
Returns
Type | Description |
---|---|
CacheItem | CacheItem |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
CacheItem item = cache.GetCacheItem(key);
GetCacheItem(String, ref CacheItemVersion)
Retrieves the specified item from the Cache object. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(6)]
public virtual CacheItem GetCacheItem(string key, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", ref version);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetCacheItem(String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(4)]
public virtual CacheItem GetCacheItem(string key, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
string textBoxValue = (string) cache.Get("MyTextBox.Value", DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
GetCacheItem(String, DSReadOption, ref CacheItemVersion)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it in the cache. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(5)]
public virtual CacheItem GetCacheItem(string key, DSReadOption dsReadOption, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
DSReadOption | dsReadOption | Options regarding reading from data source. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", DSReadOption.ReadThru, ref version);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetCacheItem(String, String, DSReadOption)
Retrieves the specified item from the Cache object.
Declaration
[TargetMethod(5)]
public virtual CacheItem GetCacheItem(string key, string providerName, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | providerName | A specific name for the data source |
DSReadOption | dsReadOption | Options regarding reading from data source |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
GetCacheItem(String, String, DSReadOption, ref CacheItemVersion)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it in the cache. It accepts the CacheItemVersion by reference. If null is passed for CacheItemVersion, then the version of the object from the cache is returned. If non-null CacheItemVersion is passed, then object is returned from the cache only if that is the current version of the object in the cache.
Declaration
[TargetMethod(7)]
public virtual CacheItem GetCacheItem(string key, string providerName, DSReadOption dsReadOption, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | providerName | A specific name for the data source |
DSReadOption | dsReadOption | Options regarding reading from data source. |
CacheItemVersion | version | The version of the object. |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
GetCacheItem(String, String, String)
Get the cache item stored in cache.
Declaration
[TargetMethod(2)]
[Obsolete("Use GetCacheItem(string key, string group, string subGroup, DSReadOption dsReadOption)")]
public virtual CacheItem GetCacheItem(string key, string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key used to reference the desired object |
System.String | group | The group of the cache item. Items with the same group are logically grouped together. |
System.String | subGroup | The sub-group within a group. |
Returns
Type | Description |
---|---|
CacheItem | CacheItem |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
CacheItem item = cache.GetCacheItem(key, "group-name", "subgroup-name");
GetCacheItem(String, String, String, DSReadOption)
Retrieves the specified item from the Cache object. If the object is read through the data source, put it against the given group and sub group.
Declaration
[TargetMethod(8)]
public virtual CacheItem GetCacheItem(string key, string group, string subGroup, DSReadOption dsReadOption)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The identifier for the cache item to retrieve. |
System.String | group | The name of the group which the item belongs to. |
System.String | subGroup | The name of the subGroup within a group. |
DSReadOption | dsReadOption | Options regarding reading from data source. |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control. The version of the cached object is also received.
Cache cache = NCache.InitializeCache("myCache");
CacheItemVersion version = null;
string textBoxValue = (string) cache.Get("MyTextBox.Value", "Customer", null, DSReadOption.ReadThru);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
GetCacheItem(String, TimeSpan, ref LockHandle, Boolean)
Get the cache item stored in cache.
Declaration
[TargetMethod(3)]
public virtual CacheItem GetCacheItem(string key, TimeSpan lockTimeout, ref LockHandle lockHandle, bool acquireLock)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key used to reference the desired object |
System.TimeSpan | lockTimeout | The TimeSpan after which the lock is automatically released. |
LockHandle | lockHandle | An instance of LockHandle to hold the lock information. |
System.Boolean | acquireLock | A flag to determine whether to acquire a lock or not. |
Returns
Type | Description |
---|---|
CacheItem | The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found. |
Remarks
///
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
LockHandle lockHandle = new LockHandle();
CacheItem item = cache.GetCacheItem("cachedItemKey",TimeSpan.FromSeconds(30) , ref lockHandle, true);
GetCacheStream(String, StreamMode)
Gets an instance of the CacheStream class.
Declaration
[TargetMethod(1)]
public virtual CacheStream GetCacheStream(string key, StreamMode streamMode)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key used to reference the stream. |
StreamMode | streamMode | Enumeration to specify the desired mode to open the stream. |
Returns
Type | Description |
---|---|
CacheStream | An instance of CacheStream |
GetCacheStream(String, StreamMode, CacheItemPriority)
Gets an instance of the CacheStream class.
Declaration
[TargetMethod(2)]
public virtual CacheStream GetCacheStream(string key, StreamMode streamMode, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key used to reference the stream. |
StreamMode | streamMode | Enumeration to specify the desired mode to open the stream. |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheStream | An instance of CacheStream |
GetCacheStream(String, StreamMode, DateTime, TimeSpan, CacheItemPriority)
Gets an instance of the CacheStream class.
Declaration
[TargetMethod(3)]
public virtual CacheStream GetCacheStream(string key, StreamMode streamMode, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key used to reference the stream. |
StreamMode | streamMode | Enumeration to specify the desired mode to open the stream. |
System.DateTime | absoluteExpiration | The time at which the added stream expires and is removed from the cache. If absolute expiration is not desired, specify Cache.NoAbsoluteExpiration |
System.TimeSpan | slidingExpiration | The interval between the time the added stream was last accessed and when it expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. If sliding expiration is not desired, specify Cache.NoSlidingExpiration |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheStream | An instance of CacheStream |
GetCacheStream(String, String, String, StreamMode, CacheItemPriority)
Gets an instance of the CacheStream class.
Declaration
[TargetMethod(4)]
public virtual CacheStream GetCacheStream(string key, string group, string subgroup, StreamMode streamMode, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key used to reference the stream. |
System.String | group | The group whose keys are to be returned. |
System.String | subgroup | |
StreamMode | streamMode | Enumeration to specify the desired mode to open the stream. |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheStream | An instance of CacheStream |
GetCacheStream(String, String, String, StreamMode, CacheDependency, DateTime, TimeSpan, CacheItemPriority)
Gets an instance of the CacheStream class.
Declaration
[TargetMethod(6)]
public virtual CacheStream GetCacheStream(string key, string group, string subGroup, StreamMode streamMode, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.String | group | The group whose keys are to be returned. |
System.String | subGroup | The sub group of the group foe which keys are to be returned. |
StreamMode | streamMode | Enumeration to specify the desired mode to open the stream. |
CacheDependency | dependency | CacheDependency to be added. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference. |
System.DateTime | absoluteExpiration | The time at which the added stream expires and is removed from the cache. If absolute expiration is not desired, specify Cache.NoAbsoluteExpiration |
System.TimeSpan | slidingExpiration | The interval between the time the added stream was last accessed and when it expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. If sliding expiration is not desired, specify Cache.NoSlidingExpiration |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheStream | An instance of CacheStream |
GetCacheStream(String, String, String, StreamMode, DateTime, TimeSpan, CacheItemPriority)
Gets an instance of the CacheStream class.
Declaration
[TargetMethod(5)]
public virtual CacheStream GetCacheStream(string key, string group, string subgroup, StreamMode streamMode, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key used to reference the stream. |
System.String | group | The group whose keys are to be returned. |
System.String | subgroup | |
StreamMode | streamMode | Enumeration to specify the desired mode to open the stream. |
System.DateTime | absoluteExpiration | The time at which the added stream expires and is removed from the cache. If absolute expiration is not desired, specify Cache.NoAbsoluteExpiration |
System.TimeSpan | slidingExpiration | The interval between the time the added stream was last accessed and when it expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. If sliding expiration is not desired, specify Cache.NoSlidingExpiration |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheStream | An instance of CacheStream |
GetConnectedClientList()
Returns the list of connected cache clients
Declaration
public virtual IList<ClientInfo> GetConnectedClientList()
Returns
Type | Description |
---|---|
System.Collections.Generic.IList<ClientInfo> | A list of ClientInfo objects of all the connected clients |
GetEnumerator()
Retrieves a dictionary enumerator used to iterate through the key settings and their values contained in the cache.
Declaration
[TargetMethod(1)]
public virtual IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | An enumerator to iterate through the Cache object. |
Remarks
If items are added or removed from the cache while enumerating through the items the behavior is not predictable. It is therefore advised not to update the cache keys while enumerating.
Note: Just like Count in a cluster especially partitioned this operation is an expensive one and may require network calls. It is therefore advised to use this method only when required.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
GetGroupData(String, String)
Retrieves the key and value pairs in a group or sub group.
Declaration
[TargetMethod(1)]
public virtual IDictionary GetGroupData(string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | group | The group whose data is to be returned. |
System.String | subGroup | The sub group of the group for which data is to be returned. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The list of key and value pairs of a group or a sub group. |
Remarks
If only group is specified, data for the group and all the sub groups of the group are returned. If both the group and sub group are specified. Only the data related to the sub group are returned.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
Hashtable table = (Hashtable) cache.GetGroupData("Customer", "Orders");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetGroupKeys(String, String)
Retrieves the keys of items in a group or sub group.
Declaration
[TargetMethod(1)]
public virtual ArrayList GetGroupKeys(string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | group | The group whose keys are to be returned. |
System.String | subGroup | The sub group of the group foe which keys are to be returned. |
Returns
Type | Description |
---|---|
System.Collections.ArrayList | The list of keys of a group or a sub group. |
Remarks
If only group is specified, keys for the group and all the sub groups of the group are returned. If both the group and sub group are specified. Only the keys related to the sub group are returned.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to retrieve the value cached for an ASP.NET text box server control.
Cache cache = NCache.InitializeCache("myCache");
ArrayList list = (ArrayList) cache.GetGroupKeys("Customer", "Orders");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
GetIfNewer(String, ref CacheItemVersion)
Gets an object from the cache only if a newer version of the object exists in cache.
Declaration
[TargetMethod(1)]
public virtual object GetIfNewer(string key, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key used to reference the desired object |
CacheItemVersion | version | The version of the desired object passed by reference. |
Returns
Type | Description |
---|---|
System.Object | If a newer object exists in the cache, the object is returned. Otherwise, null is returned. |
Examples
The following example demonstrates how to get a newer version of the item from cache if it exists.
Cache cache = NCache.InitializeCache("myCache");
cache.GetIfNewer("key", ref itemVersion);
GetIfNewer(String, String, String, ref CacheItemVersion)
Gets an object from the cache only if a newer version of the object exists in cache.
Declaration
[TargetMethod(2)]
public virtual object GetIfNewer(string key, string group, string subGroup, ref CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key used to reference the desired object |
System.String | group | The group of the cached object |
System.String | subGroup | The subGroup of the cached object |
CacheItemVersion | version | The version of the desired object passed by reference. |
Returns
Type | Description |
---|---|
System.Object | If a newer object exists in the cache, the object is returned. Otherwise, null is returned. |
Examples
The following example demonstrates how to get a newer version of the item from cache if it exists.
Cache cache = NCache.InitializeCache("myCache");
cache.GetIfNewer("key", "Alpha", null, ref itemVersion);
GetKeysByAllTags(Tag[])
Returns keys that have all the same tags in common. (Returns the Intersection set.)
Declaration
[TargetMethod(1)]
public virtual ICollection GetKeysByAllTags(Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
Tag[] | tags | An array of Tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | A collection containing cache keys. |
Examples
The following example demonstrates how to get the keys that have all the specified tags in common.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");
ICollection keys = cache.GetKeysByAllTags(tags);
GetKeysByAnyTag(Tag[])
Returns keys that have any of the same tags in common. (Returns the Union set.)
Declaration
[TargetMethod(1)]
public virtual ICollection GetKeysByAnyTag(Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
Tag[] | tags | An array of Tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | A collection containing cache keys. |
Examples
The following example demonstrates how to get the keys that have any of the specified tags in common.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");
ICollection keys = cache.GetKeysByAnyTag(tags);
GetKeysByTag(Tag)
Gets all the keys with the specified tag.
Declaration
[TargetMethod(1)]
public virtual ICollection GetKeysByTag(Tag tag)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | The tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | Returns collection containing the cache keys. |
Examples
The following example demonstrates how to get the keys with the specified tag.
Cache cache = NCache.InitializeCache("myCache");
Tag tag = new Tag("Sports");
ICollection keys = cache.GetKeysByTag(tag);
GetRunningTasks()
Get All the running tasks.
Declaration
[TargetMethod(1)]
public virtual ArrayList GetRunningTasks()
Returns
Type | Description |
---|---|
System.Collections.ArrayList | List of taskIds of running Map Reduce tasks. |
Examples
Cache _cache = NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
// Implement Map Reduce Interferaces
MapReduceTask mapReduceTask = new MapReduceTask();
IList runningTasks = _cache.GetRunningTasks();
GetTaskResult(String)
Get a Trackable instance of the task with specified taskId.
Declaration
[TargetMethod(1)]
public virtual ITrackableTask GetTaskResult(string taskId)
Parameters
Type | Name | Description |
---|---|---|
System.String | taskId | Task Id of the Map reduce task |
Returns
Type | Description |
---|---|
ITrackableTask | Returns an instance to track the task for result and status. |
Examples
Cache _cache = NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
// Implement Map Reduce Interferaces
MapReduceTask mapReduceTask = new MapReduceTask();
ITrackableTask trackableTask = _cache.ExecuteTask(mapReduceTask);
string taskID1=trackableTask.TaskId;
Random randomNumber = new Random();
string taskId2 = randomNumber.Next(2).ToString();
ITrackableTask testResult = _cache.GetTaskResult(taskId1); //returns the trackable instance
testResult = _cache.GetTaskResult(taskId12); //returns nothing as no task with such id is being running
Insert(String, CacheItem)
Add a CacheItem to the cache
Declaration
[TargetMethod(7)]
public virtual CacheItemVersion Insert(string key, CacheItem item)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add an item to the cache with a sliding expiration of 5 minutes and a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItem.
CacheItem item = new CacheItem(timeStamp);
item.SlidingExpiration = new TimeSpan(0,5,0);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("timestamp", item);
Insert(String, CacheItem, DSWriteOption, DataSourceItemsUpdatedCallback)
Add a CacheItem to the cache
Declaration
[TargetMethod(8)]
public virtual CacheItemVersion Insert(string key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback | A delegate that, if provided, is called when item is updated in data source. |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add an item to the cache with a sliding expiration of 5 minutes, a priority of high, and that notifies the application when the item is removed from the cache.
First create a CacheItem.
CacheItem item = new CacheItem(timeStamp);
item.SlidingExpiration = new TimeSpan(0,5,0);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("timestamp", item, DSWriteOption.WriteThru, new DataSourceItemsUpdatedCallback(OnDSItemsUpdated));
Insert(String, CacheItem, DSWriteOption, String, DataSourceItemsUpdatedCallback)
Declaration
[TargetMethod(9)]
public virtual CacheItemVersion Insert(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
CacheItem | item | |
DSWriteOption | dsWriteOption | |
System.String | providerName | |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback |
Returns
Type | Description |
---|---|
CacheItemVersion |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
Insert(String, CacheItem, LockHandle, Boolean)
Inserts a CacheItem to the cache if not already existing. Otherwise updates an existing item if it not already locked or if the correct lock-id is specified.
Declaration
[TargetMethod(10)]
public virtual CacheItemVersion Insert(string key, CacheItem item, LockHandle lockHandle, bool releaseLock)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
LockHandle | lockHandle | An instance of LockHandle. If the item is locked, then it can be updated only if the correct lockHandle is specified. |
System.Boolean | releaseLock | A flag to determine whether or not release lock after operation is performed. |
Returns
Type | Description |
---|---|
CacheItemVersion | The object item added to the Cache. |
Remarks
If lockId does not match with the lockId associated with cached item, an exception will be thrown.
Examples
The following example demonstrates how to update a locked item in the cache.
First create a CacheItem.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item int the cache.
theCache.Add("cachedItemKey", new CacheItem("cachedItemValue"));
Create the objects for lockid and lockdate.
LockHandle lockHandle = new LockHandle();
Get the added item from cache and acquire a lock.
object cachedItem = theCache.Get("cachedItemKey", Cache.NoLockingExpiration, ref lockHandle, true);
if (cachedItem != null)
{
try
{
theCache.Insert("cachedItemKey", new CacheItem("someothervalue"), lockHandle, true);
string cachedValue = (string)theCache.Get("cachedItemKey");
}
catch (OperationFailedException ex)
{
//Do something
}
}
Insert(String, Object)
Inserts an item into the Cache object with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration.
Declaration
[TargetMethod(2)]
public virtual CacheItemVersion Insert(string key, object value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
Returns
Type | Description |
---|---|
CacheItemVersion |
Remarks
This method will overwrite an existing Cache item with the same key
parameter.
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to insert an item into an application's cache.
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Insert(String, Object, NamedTagsDictionary)
Inserts an item into the Cache with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration. It also enables associating named tags with the object.
Declaration
[TargetMethod(1)]
public virtual CacheItemVersion Insert(string key, object value, NamedTagsDictionary namedTags)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
NamedTagsDictionary | namedTags | A NamedTagsDictionary to associate with the object. |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to add an item into an application's cache.
Cache cache = NCache.InitializeCache("myCache");
NamedTagsDictionary namedTags = new NamedTagsDictionary();
namedTags.Add("Attribute", "value");
cache.Insert("DSN", connectionString, namedTags);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Insert(String, Object, Tag[])
Inserts an item into the Cache with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration. It also enables the associating tags with the object.
Declaration
[TargetMethod(4)]
public virtual CacheItemVersion Insert(string key, object value, Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
Tag[] | tags | An array of Tag to associate with the object. |
Returns
Type | Description |
---|---|
CacheItemVersion | An instance of CacheItemVersion |
Remarks
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to add an item into an application's cache.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[1];
tags[0] = new Tag("tag-name");
cache.Insert("DSN", connectionString, tags);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Insert(String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority)
Inserts an object into the Cache with dependencies, expiration and priority policies.
Declaration
[TargetMethod(5)]
public virtual CacheItemVersion Insert(string key, object value, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
CacheDependency | dependency | The file dependencies for the inserted object. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains a null reference (Nothing in Visual Basic). |
System.DateTime | absoluteExpiration | The time at which the added object expires and is removed from the cache. |
System.TimeSpan | slidingExpiration | The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheItemVersion |
Remarks
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown. If you set the slidingExpiration
parameter to less than System.TimeSpan.Zero, or the equivalent of
more than one year, an System.ArgumentOutOfRangeException is thrown. You cannot set
both sliding and absolute expirations on the same cached item. If you do so, an
System.ArgumentException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to assign an item high priority when you insert it into your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Insert(String, Object, DateTime, TimeSpan, CacheItemPriority)
Inserts an object into the Cache with dependencies, expiration and priority policies.
Declaration
[TargetMethod(6)]
public virtual CacheItemVersion Insert(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
System.DateTime | absoluteExpiration | The time at which the added object expires and is removed from the cache. |
System.TimeSpan | slidingExpiration | The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. |
CacheItemPriority | priority | The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost. |
Returns
Type | Description |
---|---|
CacheItemVersion |
Remarks
Note: If the key
or value
parameter is null,
an System.ArgumentNullException is thrown. If you set the slidingExpiration
parameter to less than System.TimeSpan.Zero, or the equivalent of
more than one year, an System.ArgumentOutOfRangeException is thrown. You cannot set
both sliding and absolute expirations on the same cached item. If you do so, an
System.ArgumentException is thrown.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to assign an item high priority when you insert it into your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Insert(String, Object, String, String)
Insert a value to the cache
Declaration
[TargetMethod(3)]
public virtual CacheItemVersion Insert(string key, object value, string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The value that is to be stored |
System.String | group | The data group of the item |
System.String | subGroup | The data group of the item |
Returns
Type | Description |
---|---|
CacheItemVersion |
Examples
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", value, "CONNECTIONS", null);
InsertAsync(String, CacheItem, DSWriteOption, DataSourceItemsUpdatedCallback)
Insert a CacheItem to the cache asynchoronously
Declaration
[TargetMethod(2)]
public virtual void InsertAsync(string key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback | A delegate that, if provided, is called when item is updated in data source. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to insert an item into the cache asynchronously. It also provides the option to udpate the data source and registers a delegate to get the result of the data source operation.
CacheItem item = new CacheItem(connectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.SlidingExpiration = TimeSpan.Zero;
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
item.AsyncItemUpdateCallback = OnAsyncItemUpdated;
Then insert CacheItem to the cache
Cache cache = NCache.InitializeCache("myCache");
cache.InsertAsync("DSN", item, DSWriteOption.WriteThru, new DataSourceItemsUpdatedCallback(onDSItemsUpdated));
InsertAsync(String, CacheItem, String, DSWriteOption, DataSourceItemsUpdatedCallback)
Insert a CacheItem to the cache asynchoronously
Declaration
[TargetMethod(3)]
public virtual void InsertAsync(string key, CacheItem item, string providerName, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
CacheItem | item | The item that is to be stored |
System.String | providerName | The datasource name to use for write-through operation. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback | A delegate that, if provided, is called when item is updated in data source. |
InsertAsync(String, Object, AsyncItemUpdatedCallback, String, String)
Inserts an object into the Cache asynchronously with dependencies, expiration and priority policies, and a delegate you can use to notify your application when the inserted item is removed from the Cache.
Declaration
[TargetMethod(1)]
public virtual void InsertAsync(string key, object value, AsyncItemUpdatedCallback onAsyncItemUpdateCallback, string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
System.Object | value | The item to be added to the cache. |
AsyncItemUpdatedCallback | onAsyncItemUpdateCallback | A delegate that can be used to get the result of the Asynchronous update operation. |
System.String | group | An string that logically groups the data togehter. |
System.String | subGroup | The name of the subGroup within the group. |
Remarks
This is similar to Insert(String, Object) except that the operation is performed asynchronously. A ItemUpdated event is fired upon successful completion of this method.It is not possible to determine if the actual operation has failed, therefore use this operation for the cases when it does not matter much.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how to insert an item into the cache asynchronously with associated group and subGroup. It also registers a delegate to get the result of the asynchronous operation. it into your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.InsertAsync("DSN", connectionString, new AsyncItemUpdatedCallback(onAsyncItemUpdated), "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
InsertAsyncOperation(String, Object, CacheDependency, CacheSyncDependency, DateTime, TimeSpan, CacheItemPriority, DSWriteOption, CacheItemRemovedCallback, CacheItemUpdatedCallback, AsyncItemUpdatedCallback, DataSourceItemsUpdatedCallback, Boolean, String, String, Tag[], String, NamedTagsDictionary, CacheDataNotificationCallback, CacheDataNotificationCallback, EventDataFilter, EventDataFilter, String, Int16, Int16, Int16)
Function that choose the appropriate function of NCache's Cache, that need to be called according to the data provided to it.
Declaration
protected virtual void InsertAsyncOperation(string key, object value, CacheDependency dependency, CacheSyncDependency syncDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, DSWriteOption dsWriteOption, CacheItemRemovedCallback onRemoveCallback, CacheItemUpdatedCallback onUpdateCallback, AsyncItemUpdatedCallback onAsyncItemUpdateCallback, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback, bool isResyncExpiredItems, string group, string subGroup, Tag[] tags, string providerName, NamedTagsDictionary namedTags, CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, string clientId, short updateCallbackID, short removeCallbackId, short dsItemAddedCallbackID)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
System.Object | value | |
CacheDependency | dependency | |
CacheSyncDependency | syncDependency | |
System.DateTime | absoluteExpiration | |
System.TimeSpan | slidingExpiration | |
CacheItemPriority | priority | |
DSWriteOption | dsWriteOption | |
CacheItemRemovedCallback | onRemoveCallback | |
CacheItemUpdatedCallback | onUpdateCallback | |
AsyncItemUpdatedCallback | onAsyncItemUpdateCallback | |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback | |
System.Boolean | isResyncExpiredItems | |
System.String | group | |
System.String | subGroup | |
Tag[] | tags | |
System.String | providerName | |
NamedTagsDictionary | namedTags | |
CacheDataNotificationCallback | cacheItemUdpatedCallback | |
CacheDataNotificationCallback | cacheItemRemovedCallaback | |
Alachisoft.NCache.Runtime.Events.EventDataFilter | itemUpdateDataFilter | |
Alachisoft.NCache.Runtime.Events.EventDataFilter | itemRemovedDataFilter | |
System.String | clientId | |
System.Int16 | updateCallbackID | |
System.Int16 | removeCallbackId | |
System.Int16 | dsItemAddedCallbackID |
InsertBulk(String[], CacheItem[])
Insert list of CacheItem to the cache
Declaration
[TargetMethod(2)]
public virtual IDictionary InsertBulk(string[] keys, CacheItem[] items)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | returns keys that are added or updated successfully and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to assign an item high priority when you insert it into your application's Cache object. First create CacheItems.
string[] keys = {"SQLDSN", "ORADSN"};
CacheItem items[] = new CacheItem[2];
items[0] = new CacheItem(sqlConnectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
items[1] = new CacheItem(oraConnectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
item.Priority = CacheItemPriority.Low;
item.ItemRemoveCallback = onRemove;
Then insert CacheItems to the cache
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
CacheItem[] items = new CacheItem[]{myItem1, myItem2};
cache.InsertBulk(keys, items);
InsertBulk(String[], CacheItem[], DSWriteOption, DataSourceItemsUpdatedCallback)
Insert list of CacheItem to the cache
Declaration
[TargetMethod(1)]
public virtual IDictionary InsertBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback | A delegate that, if provided, is called when item is updated in data source. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | returns keys that are added or updated successfully and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to assign an item high priority when you insert it into your application's Cache object.
Note: For more information about how to use this method with the CacheItemRemovedCallback delegate, see CacheItemRemovedCallback.
First create CacheItems.string[] keys = {"SQLDSN", "ORADSN"};
CacheItem items[] = new CacheItem[2];
items[0] = new CacheItem(sqlConnectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
items[1] = new CacheItem(oraConnectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
item.Priority = CacheItemPriority.Low;
item.ItemRemoveCallback = onRemove;
Then insert CacheItems to the cache
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
CacheItem[] items = new CacheItem[]{myItem1, myItem2};
cache.InsertBulk(keys, items, DSWriteOption.WriteThru, new DataSourceItemsUpdatedCallback(onDSItemsUpdated));
InsertBulk(String[], CacheItem[], DSWriteOption, String, DataSourceItemsUpdatedCallback)
Insert list of CacheItem to the cache
Declaration
[TargetMethod(3)]
public virtual IDictionary InsertBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, string providerName, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | A unique identifier for the data source |
DataSourceItemsUpdatedCallback | onDataSourceItemUpdatedCallback | A delegate that, if provided, is called when item is updated in data source. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | returns keys that are added or updated successfully and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to assign an item high priority when you insert it into your application's Cache object.
Note: For more information about how to use this method with the CacheItemRemovedCallback delegate, see CacheItemRemovedCallback.
First create CacheItems.string[] keys = {"SQLDSN", "ORADSN"};
CacheItem items[] = new CacheItem[2];
items[0] = new CacheItem(sqlConnectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
items[1] = new CacheItem(oraConnectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
item.Priority = CacheItemPriority.Low;
item.ItemRemoveCallback = onRemove;
Then insert CacheItems to the cache
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
CacheItem[] items = new CacheItem[]{myItem1, myItem2};
cache.InsertBulk(keys, items, DSWriteOption.WriteThru, providerName, new DataSourceItemsUpdatedCallback(onDSItemsUpdated));
Invoke(String, IEntryProcessor, DSReadOption, String, DSWriteOption, String, Object[])
Execution of entry processer regardless of caching topology used, allows to execute code against a cache entry on server side without fetching any data on client side.
Declaration
[TargetMethod(1)]
public object Invoke(string key, IEntryProcessor entryProcessor, DSReadOption dsReadOption = DSReadOption.None, string readProviderName = "default", DSWriteOption dsWriteOption = DSWriteOption.None, string writeProviderName = "default", params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key of Cache entry on which the EntryProcessor is executed. |
IEntryProcessor | entryProcessor | IEntryProcessor instance |
DSReadOption | dsReadOption | Readthru option, none if not provided explicity |
System.String | readProviderName | Readthru provider name, default if not provided explicity |
DSWriteOption | dsWriteOption | Writethru option, none if not provided explicity |
System.String | writeProviderName | Writethru provider name, default if not provided explicity |
System.Object[] | arguments | Arguments list for the process. |
Returns
Type | Description |
---|---|
System.Object | Returns an instance of IEntryProcessorResult. |
Examples
Argumetns is optional. Also exception can be thrown explicitily by specifying such cases while implementing IEntryProcessor interface.
Cache _cache= NCache.InitializeCache("myCache");
//Get a new instance of sample Class implementing EntryProcessor interface.
CustomEntryProcessor myProcessor = new CustomEntryProcessor();
_cache.Insert("1", "Value1");
_cache.Insert("2", "Value2");
_cache.Insert("15", "Value3");
//Invoking the Entry processor on a single item.
Object invokerVal = _cache.Invoke("1", myProcessor);
//Invoking the Entry processor against a single item.
invokerVal = _cache.Invoke("15", myProcessor);
//Implementation of IEntryProcesser Interface
public class CustomEntryProcessor : IEntryProcessor
{
public bool IgnoreLock()
{
return true;
}
public object ProcessEntry(IMutableEntry entry, params object[] arguments)
{
if (entry.Key.Equals("1"))
{
if (entry.Exists())
{
entry.Remove();
return 0;
}
else
{
entry.Remove();
return -1;
}
}
else if (entry.Equals("15"))
{
object value = "Greater Than 10";
entry.Value = value;
return value;
}
return 1;
}
}
Invoke(String[], IEntryProcessor, DSReadOption, String, DSWriteOption, String, Object[])
Execution of entry processer regardless of caching topology used, allows to execute code against a set of cache entries on server side without fetching any data on client side.
Declaration
[TargetMethod(2)]
public virtual ICollection Invoke(string[] keys, IEntryProcessor entryProcessor, DSReadOption dsReadOption = DSReadOption.None, string readProviderName = "default", DSWriteOption dsWriteOption = DSWriteOption.None, string writeProviderName = "default", params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | Set of keys of Cache entries on which EntryProcessor will be executed. |
IEntryProcessor | entryProcessor |
|
DSReadOption | dsReadOption | Readthru option, none if not provided explicity |
System.String | readProviderName | Readthru provider name, default if not provided explicity |
DSWriteOption | dsWriteOption | Writethru option, none if not provided explicity |
System.String | writeProviderName | Writethru provider name, default if not provided explicity |
System.Object[] | arguments | Arguments list for the process. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | Returns a collection of instances of IEntryProcessorResult. |
Examples
Cache _cache= NCache.InitializeCache("myCache");
//Get a new instance of sample Class implementing EntryProcessor interface.
CustomEntryProcessor myProcessor = new CustomEntryProcessor();
string[] keys = new string[] { "1", "5", "12", "15" };
_cache.Insert(keys[0], "Value1");
_cache.Insert(keys[1], "Value1");
_cache.Insert(keys[2], "Value1");
_cache.Insert(keys[3], "Value1");
//Invoking the Entry processor against a set of items.
ICollection retEntries = _cache.Invoke(keys, myProcessor);
//Implementation of IEntryProcesser Interface
public class CustomEntryProcessor : IEntryProcessor
{
public bool IgnoreLock()
{
return true;
}
public object ProcessEntry(IMutableEntry entry, params object[] arguments)
{
if (entry.Key.Equals("1"))
{
if (entry.Exists())
{
entry.Remove();
return 0;
}
else
{
entry.Remove();
return -1;
}
}
else if (entry.Equals("15"))
{
object value = "Greater Than 10";
entry.Value = value;
return value;
}
return 1;
}
}
Lock(String, TimeSpan, out LockHandle)
Acquire a lock on an item in cache.
Declaration
[TargetMethod(1)]
public virtual bool Lock(string key, TimeSpan lockTimeout, out LockHandle lockHandle)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of cached item to be locked. |
System.TimeSpan | lockTimeout | TimeSpan after which the lock is automatically released. |
LockHandle | lockHandle | An instance of |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not lock was acquired successfully. |
Examples
Following example demonstrates how to lock a cached item.
...
LockHandle lockHandle = new LockHandle();
bool locked = theCache.lock("cachedItemKey", new TimeSpan(0,0,10), out lockHandle);
...
Log(String, String)
Declaration
public virtual void Log(string module, string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | module | |
System.String | message |
RaiseCustomEvent(Object, Object)
Broadcasts a custom application defined event.
Declaration
[TargetMethod(1)]
public virtual void RaiseCustomEvent(object notifId, object data)
Parameters
Type | Name | Description |
---|---|---|
System.Object | notifId | Application specific notification code/id |
System.Object | data | Application specific data |
Remarks
In most of the cases this method's implementation is close to O(1).
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Note: Custom event notifications can not be disabled through configuration.
Examples
The following example demonstrates how to raise a custom application defined event.
Cache cache = NCache.InitializeCache("myCache");
cache.RaiseCustomEvent(MyNotificationCodes.ConsumeItem,
new ItemData(DateTime.Now));
RegisterCacheNotification(CacheDataNotificationCallback, EventType, EventDataFilter)
Registers ItemAdded, ItemUpdate or ItemRemoved events with cache
Declaration
public virtual CacheEventDescriptor RegisterCacheNotification(CacheDataNotificationCallback cacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)
Parameters
Type | Name | Description |
---|---|---|
CacheDataNotificationCallback | cacheDataNotificationCallback | the CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache. |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Tells whether the event is to be raised on Item Added, Updated or Removed |
Alachisoft.NCache.Runtime.Events.EventDataFilter | datafilter | Tells whether to receive metadata, data with metadata or none when a notification is triggered |
Returns
Type | Description |
---|---|
CacheEventDescriptor |
Remarks
Client application can show interest in receiving events if an item is added, update or removed from the cache. As soon as the item is added, updated or removed from the cache, the client application is notified and actions can be taken accordingly.
Examples
First create an ItemCallback
ItemCallback(string key, CacheEventArg e)
{
...
}
Then register the Cache Notification
Cache cache = NCache.InitializeCache("myCache");
CacheEventDescriptor descriptor=cache.RegisterCacheNotification(new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.None);
RegisterCacheNotification(String, CacheDataNotificationCallback, EventType)
Registers the ItemUpdate or ItemRemoved events for the specified key.
Declaration
public void RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, EventType eventType)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the cache item. |
CacheDataNotificationCallback | selectiveCacheDataNotificationCallback | The CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Tells whether the event is to be raised on Item Added, Updated or Removed |
Examples
First create an ItemCallback
ItemCallback(string key, CacheEventArg e)
{
...
}
Then register the Key Notification
Cache cache = NCache.InitializeCache("myCache");
cache.RegisterCacheNotification(key, new CacheDataNotificationCallback(ItemCallback), EventType.ItemUpdated);
RegisterCacheNotification(String, CacheDataNotificationCallback, EventType, EventDataFilter)
Registers the ItemUpdate or ItemRemoved events for the specified key.
Declaration
public virtual void RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the cache item. |
CacheDataNotificationCallback | selectiveCacheDataNotificationCallback | The CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache. |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Tells whether the event is to be raised on Item Added, Updated or Removed |
Alachisoft.NCache.Runtime.Events.EventDataFilter | datafilter | Tells whether to receive metadata, data with metadata or none when a notification is triggered |
Examples
First create an ItemCallback
ItemCallback(string key, CacheEventArg e)
{
...
}
Then register the Key Notification
Cache cache = NCache.InitializeCache("myCache");
cache.RegisterCacheNotification(key, new CacheDataNotificationCallback(ItemCallback), EventType.ItemUpdated, EventDataFilter.None);
RegisterCacheNotification(String[], CacheDataNotificationCallback, EventType)
Registers the ItemUpdate or ItemRemoved events for the specified keys.
Declaration
public void RegisterCacheNotification(string[] keys, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, EventType eventType)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | An array of cache keys used to reference the cache items. |
CacheDataNotificationCallback | selectiveCacheDataNotificationCallback | The CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache. |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Tells whether the event is to be raised on item updated or removed |
Examples
First create an ItemCallback
ItemCallback(string key, CacheEventArg e)
{
...
}
Then register the Key Notification
Cache cache = NCache.InitializeCache("myCache");
string[] keys=new string[size];
cache.RegisterCacheNotification(keys,new CacheDataNotificationCallback(ItemCallback), EventType.ItemUpdated);
RegisterCacheNotification(String[], CacheDataNotificationCallback, EventType, EventDataFilter)
Registers the ItemUpdate or ItemRemoved events for the specified keys.
Declaration
public virtual void RegisterCacheNotification(string[] keys, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | An array of cache keys used to reference the cache items. |
CacheDataNotificationCallback | selectiveCacheDataNotificationCallback | The CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache. |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Tells whether the event is to be raised on item updated or removed |
Alachisoft.NCache.Runtime.Events.EventDataFilter | datafilter | This enum is to describe when registering an event, upon raise how much data is retrieved from cache when the event is raised |
Examples
First create an ItemCallback
ItemCallback(string key, CacheEventArg e)
{
...
}
Then register the Key Notification
Cache cache = NCache.InitializeCache("myCache");
string[] keys=new string[size];
cache.RegisterCacheNotification(keys,new CacheDataNotificationCallback(ItemCallback), EventType.ItemUpdated, EventDataFilter.None);
RegisterCQ(ContinuousQuery)
Registers the notifications based on the specified ContinuousQuery .
Declaration
[TargetMethod(1)]
public virtual void RegisterCQ(ContinuousQuery query)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | query | ContinuousQuery to register notifications for. |
Examples
string queryString = "SELECT MyApplication.Employee WHERE this.Salary > ?";
Hashtable values = new Hashtable();
values.Add("Salary", 50000);
ContinuousQuery query = new ContinuousQuery(queryString, values);
query.RegisterAddNotification(new ContinuousQueryItemAddedCallback(query_ItemAdded));
query.RegisterUpdateNotification(new ContinuousQueryItemUpdatedCallback(query_ItemUpdated));
query.RegisterRemoveNotification(new ContinuousQueryItemRemovedCallback(query_ItemRemoved));
cache.RegisterCQ(query);
RegisterKeyNotificationCallback(String, CacheItemUpdatedCallback, CacheItemRemovedCallback)
Registers the CacheItemUpdatedCallback and/or CacheItemRemovedCallback for the specified key.
Declaration
[Obsolete("This method is deprecated. 'Please use RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)'", false)]
public virtual void RegisterKeyNotificationCallback(string key, CacheItemUpdatedCallback updateCallback, CacheItemRemovedCallback removeCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the cache item. |
CacheItemUpdatedCallback | updateCallback | The CacheItemUpdatedCallback that is invoked if the item with the specified key is updated in the cache. |
CacheItemRemovedCallback | removeCallback | The CacheItemRemovedCallback is invoked when the item with the specified key is removed from the cache. |
Remarks
CacheItemUpdatedCallback and/or CacheItemRemovedCallback provided this way are very useful because a client application can show interest in any item already present in the cache. As soon as the item is updated or removed from the cache, the client application is notified and actions can be taken accordingly.
Remove(String)
Removes the object from the Cache.
Declaration
[TargetMethod(1)]
public virtual object Remove(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
Returns
Type | Description |
---|---|
System.Object | The item removed from the Cache. If the value in the key parameter is not found, returns a null reference (Nothing in Visual Basic). |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Remove("timestamp");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Remove(String, CacheItemVersion)
Removes an item from cache if the specified version is still the most recent version in the cache.
Declaration
[TargetMethod(5)]
public virtual object Remove(string key, CacheItemVersion version)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of item to be removed |
CacheItemVersion | version | The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache. |
Returns
Type | Description |
---|---|
System.Object | The item removed from the Cache. If the value in the key parameter is not found, returns a null reference (Nothing in Visual Basic). |
Examples
The following example demonstrates how to remove a locked item from the cache.
First create a CacheItem.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item in the cache.
theCache.Add("cachedItemKey", new "cachedItemValue");
Create the CacheItemVersion.
CacheItemVersion version = new CacheItemVersion();
Get the added item from cache and get the item version.
object cachedItem = theCache.Get("cachedItemKey", DSReadOption.None, ref version);
if (cachedItem != null)
{
try
{
//Now remove the cached item using version acquired earlier.
object removedItem = theCache.Remove("cachedItemKey", version);
}
catch (OperationFailedException ex)
{
//Do something
}
}
Remove(String, DSWriteOption, DataSourceItemsRemovedCallback)
Removes the object from the Cache.
Declaration
[TargetMethod(2)]
public virtual object Remove(string key, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating the data source. |
DataSourceItemsRemovedCallback | onDataSourceItemRemovedCallback | A delegate that, if provided, is called when item is removed from data source. |
Returns
Type | Description |
---|---|
System.Object | The item removed from the Cache. If the value in the key parameter is not found, returns a null reference (Nothing in Visual Basic). |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Remove("timestamp", DSWriteOption.None, null, "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Remove(String, DSWriteOption, String, DataSourceItemsRemovedCallback)
Removes the object from the Cache.
Declaration
[TargetMethod(3)]
public virtual object Remove(string key, DSWriteOption dsWriteOption, string providerName, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating the data source. |
System.String | providerName | Provider name. |
DataSourceItemsRemovedCallback | onDataSourceItemRemovedCallback | A delegate that, if provided, is called when item is removed from data source. |
Returns
Type | Description |
---|---|
System.Object | The item removed from the Cache. If the value in the key parameter is not found, returns a null reference (Nothing in Visual Basic). |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Remove("timestamp", DSWriteOption.None, null, "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
Remove(String, LockHandle)
Removes an item from cache if it is not already locked or if the correct lock-id is specified.
Declaration
[TargetMethod(4)]
public virtual object Remove(string key, LockHandle lockHandle)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of item to be removed |
LockHandle | lockHandle | If the item is locked then, it can be removed only if the correct lockHandle is specified. |
Returns
Type | Description |
---|---|
System.Object | The item removed from the Cache. If the value in the key parameter is not found, returns a null reference (Nothing in Visual Basic). |
Examples
The following example demonstrates how to remove a locked item from the cache.
First create a CacheItem.
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item int the cache.
theCache.Add("cachedItemKey", "cachedItemValue");
Create the lock-handle.
LockHandle lockHandle = new LockHandle();
Get the added item from cache and acquire a lock.
object cachedItem = theCache.Get("cachedItemKey", ref lockHandle, true);
if (cachedItem != null)
{
try
{
//Now remove the cached item using lockHandle acquired earlier.
object removedItem = theCache.Remove("cachedItemKey", lockHandle);
}
catch (OperationFailedException ex)
{
//Do something
}
}
RemoveAsync(String, AsyncItemRemovedCallback, DSWriteOption, DataSourceItemsRemovedCallback)
Declaration
[TargetMethod(1)]
public virtual void RemoveAsync(string key, AsyncItemRemovedCallback onAsyncItemRemoveCallback, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
AsyncItemRemovedCallback | onAsyncItemRemoveCallback | |
DSWriteOption | dsWriteOption | |
DataSourceItemsRemovedCallback | onDataSourceItemRemovedCallback |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
RemoveAsync(String, AsyncItemRemovedCallback, DSWriteOption, String, DataSourceItemsRemovedCallback)
Removes the object from the Cache asynchronously.
Declaration
[TargetMethod(2)]
public virtual void RemoveAsync(string key, AsyncItemRemovedCallback onAsyncItemRemoveCallback, DSWriteOption dsWriteOption, string providerName, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the item. |
AsyncItemRemovedCallback | onAsyncItemRemoveCallback | The delegate that can be used by the client application to get the result of the Asynchronous Remove operation. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | WriteThru provider name |
DataSourceItemsRemovedCallback | onDataSourceItemRemovedCallback | A delegate that, if provided, is called when item is removed from data source. |
Remarks
This is similar to Remove(String) except that the operation is performed asynchronously. A ItemRemoved event is fired upon successful completion of this method.It is not possible to determine if the actual operation has failed, therefore use this operation for the cases when it does not matter much.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnAsyncItemRemoved(string key, object result)
{
...
}
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.RemoveAsync("timestamp", DSWriteOption.WriteBehind, new AsyncItemRemovedCallback(OnAsyncItemRemoved), new DataSourceItemsRemovedCallback(OnDataSourceItemsRemoved), "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
RemoveBulk(String[])
Removes the objects from the Cache.
Declaration
[TargetMethod(2)]
public virtual IDictionary RemoveBulk(string[] keys)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the item. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The items removed from the Cache. If the value in the keys parameter is not found, returns a null reference (Nothing in Visual Basic). |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
cache.RemoveBulk(keys);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
RemoveBulk(String[], DSWriteOption, DataSourceItemsRemovedCallback)
Removes the objects from the Cache.
Declaration
[TargetMethod(1)]
public virtual IDictionary RemoveBulk(string[] keys, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemsRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsRemovedCallback | onDataSourceItemsRemovedCallback | A delegate that, if provided, is called when item is removed from data source. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The items removed from the Cache. If the value in the keys parameter is not found, returns a null reference (Nothing in Visual Basic). |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
cache.Remove(keys, DSWriteOption.WriteBehind, new DataSourceItemsRemovedCallback(OnDataSourceItemsRemoved), "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
RemoveBulk(String[], DSWriteOption, String, DataSourceItemsRemovedCallback)
Removes the objects from the Cache.
Declaration
[TargetMethod(3)]
public virtual IDictionary RemoveBulk(string[] keys, DSWriteOption dsWriteOption, string providerName, DataSourceItemsRemovedCallback onDataSourceItemsRemovedCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the item. |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | |
DataSourceItemsRemovedCallback | onDataSourceItemsRemovedCallback | A delegate that, if provided, is called when A unique identifier for the data source item is removed from data source. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | The items removed from the Cache. If the value in the keys parameter is not found, returns a null reference (Nothing in Visual Basic). |
Remarks
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.
Examples
The following example demonstrates how you can remove an item from your application's Cache object.
OnDataSourceItemsRemoved(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
string[] keys = new string[]{"myItem1", "myItem2"};
cache.Remove(keys, DSWriteOption.WriteBehind, new DataSourceItemsRemovedCallback(OnDataSourceItemsRemoved), "group-name", "subGroup-name");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
RemoveByAllTags(Tag[])
Removes the cached objects that have any of the same tags in common. (Returns the Union set.)
Declaration
[TargetMethod(1)]
public virtual void RemoveByAllTags(Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
Tag[] | tags | An array of Tag to search with. |
Examples
The following example demonstrates how to remove the objects that have any of the specified tags in common.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");
cache.RemoveByTag(tags);
RemoveByAnyTag(Tag[])
Removes the cached objects that have any of the same tags in common.
Declaration
[TargetMethod(1)]
public virtual void RemoveByAnyTag(Tag[] tags)
Parameters
Type | Name | Description |
---|---|---|
Tag[] | tags | An array of Tag to search with. |
Examples
The following example demonstrates how to remove the objects that have any of the specified tags in common.
Cache cache = NCache.InitializeCache("myCache");
Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");
cache.RemoveByTag(tags);
RemoveByTag(Tag)
Removes the cached objects with the specified tag.
Declaration
[TargetMethod(1)]
public virtual void RemoveByTag(Tag tag)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | A Tag to search with. |
Examples
The following example demonstrates how to remove the objects with the specified tag.
Cache cache = NCache.InitializeCache("myCache");
Tag tag = new Tag("Alpha");
cache.RemoveByTag(tag);
RemoveGroupData(String, String)
Remove the group from cache.
Declaration
[TargetMethod(1)]
public virtual void RemoveGroupData(string group, string subGroup)
Parameters
Type | Name | Description |
---|---|---|
System.String | group | group to be removed. |
System.String | subGroup | subGroup to be removed. |
Search(String, IDictionary)
Performs search on the Cache based on the query specified.
Declaration
[TargetMethod(1)]
[Obsolete("use ExecuteReader instead")]
public virtual ICollection Search(string query, IDictionary values)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of atribute names and values. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | Returns a list of cache keys |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Hashtable values = new Hashtable();
values.add("Name", "Paul Jones");
"select Test.Application.Employee where this.Name = ?"
values.add("Salary", 2000);
"select Test.Application.Employee where this.Salary > ?"
values.Add("Name", "Paul jones");
values.Add("Salary", 2000);
"select Test.Application.Employee where this.Name = ? and this.Salary > ?"
values.Add("Name", "Paul Jones");
values.Add("Salary", 2000);
"select Test.Application.Employee where Not(this.Name = 'Paul Jones' and this.Salary > 2000)"
SearchCQ(ContinuousQuery)
Performs search on the Cache based on the specified ContinuousQuery and registers the notifications.
Declaration
[TargetMethod(1)]
[Obsolete("use ExecuteReaderCQ instead")]
public virtual ICollection SearchCQ(ContinuousQuery query)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | query | ContinuousQuery to perform the search and register notifications for. |
Returns
Type | Description |
---|---|
System.Collections.ICollection |
Examples
string queryString = "SELECT MyApplication.Employee WHERE this.Salary > ?";
Hashtable values = new Hashtable();
values.Add("Salary", 50000);
ContinuousQuery query = new ContinuousQuery(queryString, values);
query.RegisterAddNotification(new ContinuousQueryItemAddedCallback(query_ItemAdded));
query.RegisterUpdateNotification(new ContinuousQueryItemUpdatedCallback(query_ItemUpdated));
query.RegisterRemoveNotification(new ContinuousQueryItemRemovedCallback(query_ItemRemoved));
ICollection results = cache.SearchCQ(query);
SearchEntries(String, IDictionary)
Declaration
[TargetMethod(1)]
[Obsolete("Use ExecuteReader instead")]
public virtual IDictionary SearchEntries(string query, IDictionary values)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | |
System.Collections.IDictionary | values |
Returns
Type | Description |
---|---|
System.Collections.IDictionary |
Examples
To create an instance of Cache class you can use code as follows:
Cache cache = NCache.InitializeCache("myReplicatedCache");
Application[�CacheHandle�] = cache;
SearchEntriesCQ(ContinuousQuery)
Performs search on the Cache based on the specified ContinuousQuery and registers the notifications.
Declaration
[TargetMethod(1)]
[Obsolete("Use ExecuteReaderCQ instead")]
public virtual IDictionary SearchEntriesCQ(ContinuousQuery query)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | query | ContinuousQuery to perform the search and register notifications for. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary |
Examples
string queryString = "SELECT MyApplication.Employee WHERE this.Salary > ?";
Hashtable values = new Hashtable();
values.Add("Salary", 50000);
ContinuousQuery query = new ContinuousQuery(queryString, values);
query.RegisterAddNotification(new ContinuousQueryItemAddedCallback(query_ItemAdded));
query.RegisterUpdateNotification(new ContinuousQueryItemUpdatedCallback(query_ItemUpdated));
query.RegisterRemoveNotification(new ContinuousQueryItemRemovedCallback(query_ItemRemoved));
IDictionary results = cache.SearchEntriesCQ(query);
SetAttributes(String, CacheItemAttributes)
Add Attribute existing cache item.
Declaration
[TargetMethod(1)]
public virtual bool SetAttributes(string key, CacheItemAttributes attributes)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key used to reference the required object |
CacheItemAttributes | attributes | Set of attribute to be added |
Returns
Type | Description |
---|---|
System.Boolean | True if the operation successeded otherwise false |
ToString()
The string representation of the cache object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
Unlock(String)
Forcefully unlocks a locked cached item.
Declaration
[TargetMethod(1)]
public virtual void Unlock(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of a cached item to be unlocked |
Examples
Following example demonstrates how to unlock a cached item.
...
theCache.Unlock("cachedItemKey");
...
Unlock(String, LockHandle)
Unlocks a locked cached item if the correct lock-id is specified.
Declaration
[TargetMethod(2)]
public virtual void Unlock(string key, LockHandle lockHandle)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | key of a cached item to be unlocked |
LockHandle | lockHandle | An instance of LockHandle that was generated when lock was acquired. |
Examples
Following example demonstrates how to unlock a cached item.
...
theCache.Unlock("cachedItemKey", lockHandle);
...
UnRegisterCacheNotification(CacheEventDescriptor)
Unregisters a cache level event that may have been registered
Declaration
public virtual void UnRegisterCacheNotification(CacheEventDescriptor discriptor)
Parameters
Type | Name | Description |
---|---|---|
CacheEventDescriptor | discriptor | The descriptor returned when the general event was registered |
Examples
Let us consider you registered an event against a cache
Cache cache = NCache.InitializeCache("myCache");
CacheEventDescriptor eDescriptor=cache.RegisterCacheNotification(new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.None);
Now, Unregister this event by using the CacheEventDescriptor returned by regitering the event
cache.UnRegisterCacheNotification(eDescriptor);
UnRegisterCacheNotification(String, CacheDataNotificationCallback, EventType)
Unregisters event that may have been registered against a specific key
Declaration
public virtual void UnRegisterCacheNotification(string key, CacheDataNotificationCallback callback, EventType eventType)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the cache item |
CacheDataNotificationCallback | callback | The CacheDataNotificationCallback that was specified while registering the event. |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Type of the event to unregister |
Examples
Let us consider you registered an event against a key
Cache cache = NCache.InitializeCache("myCache");
cache.RegisterCacheNotification(key, new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.None);
Now, Unregister this event by providing the key, callback and eventtype
cache.UnRegisterCacheNotification(key, new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded);
UnRegisterCacheNotification(String[], CacheDataNotificationCallback, EventType)
Unregisters any event that may have been registered by the user against multiple cache keys
Declaration
public virtual void UnRegisterCacheNotification(string[] key, CacheDataNotificationCallback callback, EventType eventType)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | key | An array of cache keys used to reference the cache itemst |
CacheDataNotificationCallback | callback | The CacheDataNotificationCallback that was specified while registering the event. |
Alachisoft.NCache.Runtime.Events.EventType | eventType | Type of event to unregister |
Examples
Let us consider you registered an event against a bulk of keys
Cache cache = NCache.InitializeCache("myCache");
string[] keys=new string[size];
cache.RegisterCacheNotification(keys, new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.None);
Now, Unregister this event by providing the key, callback and eventtype
cache.UnRegisterCacheNotification(keys, new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded);
UnRegisterCQ(ContinuousQuery)
Unregisters notifications for the specified ContinuousQuery.
Declaration
[TargetMethod(1)]
public virtual void UnRegisterCQ(ContinuousQuery query)
Parameters
Type | Name | Description |
---|---|---|
ContinuousQuery | query | ContinuousQuery to unregister notifications for. |
Examples
string queryString = "SELECT MyApplication.Employee WHERE this.Salary > ?";
Hashtable values = new Hashtable();
values.Add("Salary", 50000);
ContinuousQuery query = new ContinuousQuery(queryString, values);
query.RegisterAddNotification(new ContinuousQueryItemAddedCallback(query_ItemAdded));
query.RegisterUpdateNotification(new ContinuousQueryItemUpdatedCallback(query_ItemUpdated));
query.RegisterRemoveNotification(new ContinuousQueryItemRemovedCallback(query_ItemRemoved));
cache.RegisterCQ(query);
cache.UnRegisterCQ(query);
UnRegisterKeyNotificationCallback(String, CacheItemUpdatedCallback, CacheItemRemovedCallback)
Unregisters the CacheItemUpdatedCallback and/or CacheItemRemovedCallback already registered for the specified key.
Declaration
public virtual void UnRegisterKeyNotificationCallback(string key, CacheItemUpdatedCallback updateCallback, CacheItemRemovedCallback removeCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The cache key used to reference the cache item. |
CacheItemUpdatedCallback | updateCallback | CacheItemUpdatedCallback that is invoked when the item with the specified key is updated in the cache. |
CacheItemRemovedCallback | removeCallback | CacheItemRemovedCallback that is invoked when the item with the key is removed from the cache. |
UnRegisterKeyNotificationCallback(String[], CacheItemUpdatedCallback, CacheItemRemovedCallback)
Unregisters the CacheItemUpdatedCallback and/or CacheItemRemovedCallback already registered for the specified list of keys.
Declaration
public virtual void UnRegisterKeyNotificationCallback(string[] keys, CacheItemUpdatedCallback updateCallback, CacheItemRemovedCallback removeCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache key used to reference the cache item. |
CacheItemUpdatedCallback | updateCallback | CacheItemUpdatedCallback that is invoked when the item with the specified key is updated in the cache. |
CacheItemRemovedCallback | removeCallback | CacheItemRemovedCallback that is invoked when the item with the key is removed from the cache. |
CacheCleared
Occurs after the Cache is cleared.
Declaration
public virtual event CacheClearedCallback CacheCleared
Event Type
Type | Description |
---|---|
CacheClearedCallback |
Remarks
You can use this event to perform tasks when the Cache is cleared.
Since this callback is invoked every time an item is removed from the Cache, doing a lot of processing inside the callback might have an impact on the performance of the cache and cluster. It is therefore advisable to do minimal processing inside the handler.
For more information on how to use this callback see the documentation for CacheClearedCallback.CacheClientConnectivityChanged
Event raised when a cache client connets to or disconnect from cache. (Raised only for outproc caches)
Declaration
public virtual event CacheClientConnectivityChangedCallback CacheClientConnectivityChanged
Event Type
Type | Description |
---|---|
CacheClientConnectivityChangedCallback |
CacheStopped
Occurs after the cache has been stopped.
Declaration
public virtual event CacheStoppedCallback CacheStopped
Event Type
Type | Description |
---|---|
CacheStoppedCallback |
Remarks
You can use this event to perform the tasks when a the cache has been stopped.
This callback is invoked when the cache has either been stopped intentionally or connection with the server has been lost due to some reason so that you can connect to another server.
For more information on how to use this callback see the documentation for CacheStoppedCallback.CustomEvent
Occurs in response to a RaiseCustomEvent(Object, Object) method call.
Declaration
public virtual event CustomEventCallback CustomEvent
Event Type
Type | Description |
---|---|
CustomEventCallback |
Remarks
You can use this event to handle custom application defined event notifications.
Doing a lot of processing inside the handler might have an impact on the performance of the cache and cluster. It is therefore advisable to do minimal processing inside the handler.
For more information on how to use this callback see the documentation for CustomEventCallback.ItemAdded
Occurs after an item has been added to the Cache.
Declaration
[Obsolete("This method is deprecated. 'Please use RegisterCacheNotification(CacheDataNotificationCallback cacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)", false)]
public virtual event CacheItemAddedCallback ItemAdded
Event Type
Type | Description |
---|---|
CacheItemAddedCallback |
Remarks
You can use this event to perform tasks when an item is added to the Cache.
Since this callback is invoked every time an item is removed from the Cache, doing a lot of processing inside the callback might have an impact on the performance of the cache and cluster. It is therefore advisable to do minimal processing inside the handler.
For more information on how to use this callback see the documentation for CacheItemAddedCallback.ItemRemoved
Occurs after an has been removed from the Cache.
Declaration
[Obsolete("This method is deprecated. 'Please use RegisterCacheNotification(CacheDataNotificationCallback cacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)", false)]
public virtual event CacheItemRemovedCallback ItemRemoved
Event Type
Type | Description |
---|---|
CacheItemRemovedCallback |
Remarks
You can use this event to perform tasks when an item is removed from the Cache.
Since this callback is invoked every time an item is removed from the Cache, doing a lot of processing inside the callback might have an impact on the performance of the cache and cluster. It is therefore advisable to do minimal processing inside the handler.
Note: If an item is removed from the Cache for which a callback is supplied as parameter to Add(String, Object) or Insert(String, Object) method; that callback will be invoked instead of this callback.
For more information on how to use this callback see the documentation for CacheItemRemovedCallback.ItemUpdated
Occurs after an item has been updated in the Cache.
Declaration
[Obsolete("This method is deprecated. 'Please use RegisterCacheNotification(CacheDataNotificationCallback cacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)", false)]
public virtual event CacheItemUpdatedCallback ItemUpdated
Event Type
Type | Description |
---|---|
CacheItemUpdatedCallback |
Remarks
You can use this event to perform tasks when an item is updated in the Cache.
Since this callback is invoked every time an item is removed from the Cache, doing a lot of processing inside the callback might have an impact on the performance of the cache and cluster. It is therefore advisable to do minimal processing inside the handler.
For more information on how to use this callback see the documentation for CacheItemUpdatedCallback.MemberJoined
Occurs after a new node has joined the cluster.
Declaration
public virtual event MemberJoinedCallback MemberJoined
Event Type
Type | Description |
---|---|
MemberJoinedCallback |
Remarks
You can use this event to perform the tasks when a new node joins the cluster.
This callback is invoked every time a node joins the cluster. As part of the callback you receive the port at which the new node accepts the remote client connections.
For more information on how to use this callback see the documentation for MemberJoinedCallback.MemberLeft
Occurs after a node has left the cluster.
Declaration
public virtual event MemberLeftCallback MemberLeft
Event Type
Type | Description |
---|---|
MemberLeftCallback |
Remarks
You can use this event to perform the tasks when a node leaves the cluster.
This callback is invoked every time an existing node leaves the cluster.
For more information on how to use this callback see the documentation for MemberLeftCallback.