C# 过期本地存储+;windows phone

C# 过期本地存储+;windows phone,c#,silverlight,xaml,windows-phone-7.1,windows-phone-8,C#,Silverlight,Xaml,Windows Phone 7.1,Windows Phone 8,我像缓存一样使用本地存储来持久化数据: public void AddtoFavorite(Flight FavoriteFlight) { try { XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; using (IsolatedStor

我像缓存一样使用本地存储来持久化数据:

 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;
        }

    }
我需要localstorage每24小时过期一次,以引用localstorage的值,请问您如何做到这一点


关于

当您将
航班
对象保存到独立存储时,只需将
保存日期
字段添加到您的
航班
对象中,并在检索该对象时检查它是否在24小时之前

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))
                    {
                        FavoriteFlight.SavedDate = DateTime.Now;
                        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);

                   if ((DateTime.Now - fav.SavedDate).TotalHours > 24)
                   {
                       // TODO: Refresh the value
                   }

                   result.FlightFavorite = fav;
                   result.Date = result.FlightFavorite.ArrivalOrDepartDateTime.ToString("dd/MM/yyyy");
                   result.VisibleFavorite = true;
                   return result;

                }
            }    
        }
        catch
        {
            return result;
        }

}