ArrayList values=new ArrayList();
IsolatedStorageFileStream stream = null;
try{
stream = new IsolatedStorageFileStream(_storeFile,FileMode.Open);
}catch(Exception e){}
if(null!=stream){
values=(ArrayList)BinarySerializer.DeSerialize(stream);
stream.Close();
}
//保存数据
IsolatedStorageFileStream stream;
stream = new IsolatedStorageFileStream(_stroeFile,FileMode.OpenOrCreate);
ArrayList values = new ArrayList();
values.Add("test1");
......
BinarySerializer.Serializer(values,stream);
stream.Close();
使用上例时注意需要引入名称空间:
System.IO;
System.IO.IsolatedStorage;
System.Runtime.Serialization.Formatters;
6).离线数据同步
现在这个版本的myweb还不支持自动地实现同步。
可以用myweb.Connected属性判断当前是否连在网上。
六、Cache服务
Caching动态产生的内容叫output catching。
Caching专门的对象叫Data Catching。
asp+中提供了专门的Cache引擎。
1).output caching
设置response的expiration/validation,仅对GET和HEAD有效,支持URL中的参数,完全相同
时使用catching中的内容。内容缺省地将在cache中保存60分钟。
要让一个.aspx文件被caching,仅需要加一行:
<%@ OutputCache Duration="60" %>
上面的60指60秒。
要实现更多的控制,如下:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
或者:
SetExpires(DateTime.Now.AddSeconds(60));
SetCacheability(HttpCacheability.Public);
SetSlidingExpiration(true);
2).Data Caching
Cache引擎可以让你把对象保存到其中,只有应用重启后才需要重建Cache。是一个字典接口,如:
Ca
| 对此文章发表了评论 |
