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 and False if operation failed. |
Examples
Example demonstrates how to update Absolute Expiration of 5 minutes on an existing item in cache.
ICache cache = CacheManager.GetCache("myCache");
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))
{
...
}