ASP.NET自定义输出缓存提供程序(2)
foreach (var discarded in discardedList)
{
Remove(discarded.Key);
DateTime discardedDate;
cacheExpireList.TryRemove(discarded.Key,
out discardedDate);
}
};
timer.Start();
}
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存的键</param>
/// <param name="entry">缓存的对象</param>
/// <param name="utcExpiry">过期时间</param>
/// <returns>返回缓存值</returns>
public override object Add(string key, object entry,
DateTime utcExpiry)
{
FileStream fs = new FileStream(
String.Format("{0}{1}.binary", cachePath, key),
FileMode.Create, FileAccess.Write);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, entry);
fs.Close();
cacheExpireList.TryAdd(key, utcExpiry.ToLocalTime());
return entry;
}
/// <summary>
/// 获得缓存值
/// </summary>
/// <param name="key">缓存键</param>
/// <returns>缓存值</returns>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>