Method Add
Add(String, Object)
Adds an item into the Cache object with a cache key to reference its location.
Declaration
CacheItemVersion Add(string key, object value)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | Unique key to identify the cache item. |
System. |
value | The item (object) to be stored in the cache. |
Returns
Type | Description |
---|---|
Cache |
Represents the version of each cache item. |
Examples
Example demonstrates how to add a value to cache.
ICache cache = CacheManager.GetCache("myCache");
Product product = new Product();
product.Id = 1;
product.Name = "Chai";
string key = "Product0";
cache.Add(key, product);
Add(String, CacheItem, WriteThruOptions)
Adds a Cache
Declaration
CacheItemVersion Add(string key, CacheItem item, WriteThruOptions writeThruOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | Unique key to identify the cache item. |
Cache |
item | Cache |
Write |
writeThruOptions | Write |
Returns
Type | Description |
---|---|
Cache |
Remarks
If CacheItem contains invalid values, the related exception is thrown.
See Cache
Examples
Example demonstrates how to add an item to the cache with a sliding expiration of 5 minutes, a priority of high.
ICache cache = CacheManager.GetCache("myCache");
Product product = new Product();
product.Id = 1;
product.Name = "Chai";
CacheItem item = new CacheItem(product);
item.Expiration = new Expiration(ExpirationType.Sliding,new TimeSpan(0, 5, 0));
item.Priority = CacheItemPriority.High;
string key = "Product0";
WriteThruOptions writeThruOptions = new WriteThruOptions(WriteMode.WriteThru, "ProdDataSource1");
cache.Add(key, item, writeThruOptions);