Method UpdateAttributes
UpdateAttributes(String, CacheItemAttributes)
Update CacheItemAttributes of an existing item in cache.
Declaration
bool UpdateAttributes(string key, CacheItemAttributes attributes)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Unique key to identify the cache item. |
CacheItemAttributes | attributes | An instance ofCacheItemAttributes to update item in the cache. |
Returns
Type | Description |
---|---|
System.Boolean | Flag that determines status of the update operation. True if attributes of the item in cache was updated successfully otherwise False . |
Examples
Example demonstrates how to update absolute expiration of 5 minutes on an existing item in cache.
ICache cache = CacheManager.GetCache("demoCache");
Product product = new Product();
product.Id = 1;
product.Name = "Chai";
string key = "Product0";
cache.Insert(key, product);
CacheItemAttributes attributes = new CacheItemAttributes();
attributes.AbsoluteExpiration = DateTime.Now.AddMinutes(5);
if(cache.UpdateAttributes(key, attributes))
{
...
}