New Posts New Posts RSS Feed: Silverlight Isolated Storage not reading from cache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Silverlight Isolated Storage not reading from cache

 Post Reply Post Reply
Author
DataMan View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Jul-2007
Location: Canada
Posts: 52
Post Options Post Options   Quote DataMan Quote  Post ReplyReply Direct Link To This Post Topic: Silverlight Isolated Storage not reading from cache
    Posted: 15-Aug-2010 at 8:47pm
Hopefully this will clean up.
 
  public void SaveCache()
        {
            try
            {
                IsolatedStorageFile isoFile;
                isoFile = IsolatedStorageFile.GetUserStoreForApplication();
                IsolatedStorageFileStream isoStream =
                    new IsolatedStorageFileStream("Data.bin",
                    FileMode.Create,
                    FileAccess.Write,
                    isoFile);
                _entityManager.CacheStateManager.SaveCacheState(isoStream, true);
                              
                isoFile.Dispose();
              
            }
            catch (IsolatedStorageException ex)
            {
                // Add code here to handle the exception.
                Console.WriteLine(ex);
            }
        }
        private void RestoreCache()
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists("DD_Data.bin"))
                {
                    using (var stream = store.OpenFile("Data.bin", FileMode.Open))
                    {
                        _entityManager.CacheStateManager.RestoreCacheState(stream, RestoreStrategy.Normal, true);
                    }
                }
            }
        }
 
Before I close the application I move around in the records and then I click the save to cache button and it saves without any exceptions.  When I open the application again I click the restore button and it goes through the code without any errors.
 
The issue I see is that even though I restored the cache the fetch event in the logs is still showing records being pulled from the datasource.  When I click into the record I saved and then away,  the second time it says getting from cache.  The first time it should say getting from cache because it was saved then restored.
 
Any thoughts on how to fix?
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 17-Aug-2010 at 6:54pm
The QueryCache is not serialized when the EntityCacheState is saved, so after restoring the cache, DevForce does not know if it is safe to satisfiy the query from cache.  There are some subtleties with cache coherency and merging, so we do not provide the ability yet to serialize the QueryCache, but this is something we are looking into.
 
This may not apply to this circumstance, but as part of the discussion, there are several ways to control the caching behavior:
 
1)  Specify the QueryStrategy for an EntityQuery - e.g. query.With(QueryStrategy.CacheOnly)
2)  Specify the QueryStrategy for the EntityManager - e.g. manager.DefaultQueryStrategy = QueryStrategy.CacheOnly;
3)  Add an EntityQuery to the QueryCache - e.g. manager.QueryCache.Add(query)
4)  Disconnect the EntityManager forcing everything to go to cache - e.g. manager.Disconnect()
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down