Print Page | Close Window

Silverlight Isolated Storage not reading from cache

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2067
Printed Date: 21-Apr-2026 at 11:51pm


Topic: Silverlight Isolated Storage not reading from cache
Posted By: DataMan
Subject: Silverlight Isolated Storage not reading from cache
Date 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?



Replies:
Posted By: ting
Date 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()
 



Print Page | Close Window