读书人

这段代码是什么意思?该怎么解决

发布时间: 2012-03-30 17:32:10 作者: rapoo

这段代码是什么意思?
<%@ Import Namespace="System.Data" %>

<script language="C#" runat="server">
static Cache _cache;
static string _path;

void Application_Start ()
{
_cache = Context.Cache;
_path = Context.Server.MapPath ("Stocks.xml");

DataSet ds = new DataSet ();
ds.ReadXml (_path);

_cache.Insert ("Stocks", ds, new CacheDependency (_path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshDataSet));
}

static void RefreshDataSet (String key, Object item,
CacheItemRemovedReason reason)
{
DataSet ds = new DataSet ();
ds.ReadXml (_path);

_cache.Insert ("Stocks", ds, new CacheDependency (_path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshDataSet));
}
</script>

谁能够帮我详细解释一下这段代码的工作流程?
越详细越好!

[解决办法]
缓存读写XML
[解决办法]

C# code
  _cache = Context.Cache;      _path = Context.Server.MapPath ("Stocks.xml");  //xml文件路径      DataSet ds = new DataSet ();      ds.ReadXml (_path);   //加xml文件转化到ds中      //插入缓存      //参数意思:     // Cache.Insert 方法 (String, Object, CacheDependency, DateTime, TimeSpan, //CacheItemPriority, CacheItemRemovedCallback)//向 Cache 对象中插入对象,后者具有依赖项、过期和优先级策略以及一个委托(可用于在从 Cache 移除插//入项时通知应用程序)。       _cache.Insert ("Stocks", ds, new CacheDependency (_path),          Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,          CacheItemPriority.Default,          new CacheItemRemovedCallback (RefreshDataSet));
[解决办法]
<%@ Import Namespace="System.Data" %>

<script language="C#" runat="server">
static Cache _cache;
static string _path;

void Application_Start ()
{
_cache = Context.Cache; //缓存
_path = Context.Server.MapPath ("Stocks.xml"); //XML地址

DataSet ds = new DataSet ();
ds.ReadXml (_path); //读取XML

_cache.Insert ("Stocks", ds, new CacheDependency (_path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshDataSet)); //设置缓存依赖项等相关信息
}

//回调函数
static void RefreshDataSet (String key, Object item,
CacheItemRemovedReason reason)
{
DataSet ds = new DataSet ();
ds.ReadXml (_path);

_cache.Insert ("Stocks", ds, new CacheDependency (_path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Default,
new CacheItemRemovedCallback (RefreshDataSet));
}
</script>

[解决办法]
楼上回答不错
[解决办法]
用函数RefreshDataSet()来进行xml的缓存、读写;
[解决办法]
读取XML数据到dataset,添加到缓存
再CacheDependency跟踪缓存依赖项
使用RefreshDataSet 更新缓存


[解决办法]
http://msdn.microsoft.com/zh-cn/library/system.web.caching.cache.insert(VS.80).aspx
[解决办法]
XML依赖缓存 当XML发现变化时自动更新缓存

读书人网 >asp.net

热点推荐