Write to file when cache expires
How 开发者_如何学运维to write to a file the content of cache when Cache expires.
I'm assuming you're using ASP.Net, and you would like to write the content of a particular cached item?
To accomplish this, insert the item into the cache with a callback function specified for when the item is removed. For example:
Cache.Insert("MyText", someTextVariable, null, DateTime.Now.AddSeconds(10),
TimeSpan.Zero, CacheItemPriority.High,
new CacheItemRemovedCallback(ItemRemoved))
public void ItemRemoved(string key, object value, CacheItemRemovedReason reason)
{
// write value to file
}
If this isn't what you're talking about, you're going to have to give more details in your question, because it's pretty vague.
精彩评论