我正在使用像缓存一样的本地存储来持久化数据:
public void AddtoFavorite(Flight FavoriteFlight)
{
try
{
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Favorite.xml", FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(Flight));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(xmlWriter, FavoriteFlight);
}
}
}
}
catch (Exception ex)
{
}
}
以及这种获取数据的方法:
public FavoriteFlight GetFavorite()
{
FavoriteFlight result = new FavoriteFlight();
result.VisibleFavorite = false;
try
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Favorite.xml", FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(Flight));
Flight fav=(Flight)serializer.Deserialize(stream);
result.FlightFavorite = fav;
result.Date = result.FlightFavorite.ArrivalOrDepartDateTime.ToString("dd/MM/yyyy");
result.VisibleFavorite = true;
return result;
}
}
}
catch
{
return result;
}
}
我需要本地存储每 24 小时过期一次以引用本地存储的值,请问你该怎么做?
问候