开发者

Write to file when cache expires

开发者 https://www.devze.com 2022-12-19 06:04 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号