public Object Add ( string key, Object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback )
ArrayList myarray = new ArrayList();
myarray.Add("1.学习天地1");
myarray.Add("2.学习天地1");
myarray.Add("3.学习天地1");
myarray.Add("4.学习天地1");
string item = "这是一条缓存";
Cache["item"] = item;//赋值
Response.Write(Cache.Get("item") + "<br/>");
item = "更改一条缓存数据";
Cache.Insert("item", item);//更改缓存值
Response.Write(Cache.Get("item") + "<br/>");
//Cache.Remove("item"); //移除缓存值
//Response.Write(Cache.Get("item") + "<br/>");
Response.Write(Cache["item"].GetType().Name + "<br/>");//GetType获得Cache的数据类型
Response.Write(Cache.Get("Array") + "<br/>");//GetType获得Cache的数据类型
IDictionaryEnumerator bianli = Cache.GetEnumerator();//遍历整个缓存
while (bianli.MoveNext())
{
Response.Write(bianli.Value + "<br/>");
}
Response.Write("获取缓存数量:" + Cache.Count);
if (Cache["Array"] == null)
{//当缓存Array不存在时,添加缓存,缓存时间设定为5秒
Cache.Add("Array", myarray, null, DateTime.Now.AddSeconds(5), TimeSpan.Zero, CacheItemPriority.Normal, null);
}
<?xml version="1.0" encoding="utf-8" ?> <book> <bookinfo> <name>英国古代</name> <price>28.00</price> </bookinfo> <bookinfo> <name>中国历史</name> <price>20.00</price> </bookinfo> <bookinfo> <name>中国历史1232sdf2</name> <price>20.00</price> </bookinfo> </book>
private static CacheDependency Mydata;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("Cachexml.xml"));//读取Xml里面数据
if (Cache["CXml"] == null)
{
//创建缓存依赖项
Mydata = new CacheDependency(Server.MapPath("Cachexml.xml"));
Cache.Add("CXml", ds, Mydata, DateTime.Now.AddSeconds(10), TimeSpan.Zero, CacheItemPriority.Normal, null);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Mydata.HasChanged)
{//判断缓存是否更改
Response.Write("缓存已经更改,更改时间为"+Mydata.UtcLastModified);//获取缓存的跟新时间
}
if (Cache["CXml"] == null)
{//当xml文件被改动时缓存从新加载
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("Cachexml.xml"));//读取Xml里面数据
//创建缓存依赖项
Mydata = new CacheDependency(Server.MapPath("Cachexml.xml"));
Cache.Add("CXml", ds, Mydata, DateTime.Now.AddSeconds(60), TimeSpan.Zero, CacheItemPriority.Normal, null);
}
this.GridView1.DataSource = Cache["CXml"];
this.GridView1.DataBind();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有