Adding Tagged Data
To utilize the APIs, include the following namespace in your application:
Alachisoft.NCache.Runtime.Caching.
The following tags are used in the succeeding examples:
// Create a Tag array and specify tags.
Tag[] productTags = new Tag[2];
productTags[0] = new Tag("Product");
productTags[1] = new Tag("Beverages");
Adding Items to Cache with Tags
In this example, Add
operation overload is used to associate tags that were
previously created.
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Chai";
string key = "Product:" + product.ProductID;
try{
cache.Add(key, product, productTags);
}
catch (OperationFailedException ex){
// handle exception
}
Tagging Data through CacheItem
In this example, tags are set by assigning them to the CacheItem
.
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Chai";
string key = "Product:" + product.ProductID;
CacheItem cacheItem = new CacheItem(product);
cacheItem.Tags = productTags;
try{
cache.Add(key, cacheItem);
}
catch (OperationFailedException ex){
// handle exception
}